Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Make sure all threadpool tasks are complete upon starting or endling …
Browse files Browse the repository at this point in the history
…an activity
  • Loading branch information
Causeless committed Dec 29, 2023
1 parent c618c12 commit 2d7ddfd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Managers/ActivityMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d7ddfd

Please sign in to comment.