From 2d7ddfd9f5f3ed4f70a083bedd51b315eb8d4929 Mon Sep 17 00:00:00 2001 From: Causeless Date: Fri, 29 Dec 2023 17:44:22 +0000 Subject: [PATCH] Make sure all threadpool tasks are complete upon starting or endling an activity --- Managers/ActivityMan.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Managers/ActivityMan.cpp b/Managers/ActivityMan.cpp index 7208029b1..a361bfda2 100644 --- a/Managers/ActivityMan.cpp +++ b/Managers/ActivityMan.cpp @@ -297,6 +297,9 @@ namespace RTE { int ActivityMan::StartActivity(Activity *activity) { RTEAssert(activity, "Trying to start a null activity!"); + g_ThreadMan.GetPriorityThreadPool().wait_for_tasks(); + g_ThreadMan.GetBackgroundThreadPool().wait_for_tasks(); + // Stop all music played by the current activity. It will be re-started by the new Activity. g_AudioMan.StopMusic(); @@ -442,6 +445,9 @@ namespace RTE { void ActivityMan::EndActivity() const { // TODO: Set the activity pointer to nullptr so it doesn't return junk after being destructed. Do it here, or wherever works without crashing. if (m_Activity) { + g_ThreadMan.GetPriorityThreadPool().wait_for_tasks(); + g_ThreadMan.GetBackgroundThreadPool().wait_for_tasks(); + m_Activity->End(); g_ConsoleMan.PrintString("SYSTEM: Activity \"" + m_Activity->GetPresetName() + "\" was ended"); } else {