From f9f26ad50bcd712b4825313bbb85a2a14561f974 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 28 May 2026 17:36:28 +0200 Subject: [PATCH] Fix crash on shutdown StopAllMacros was called before th->wait(), allowing Macro::Stop() to run concurrently with the other threads still inside CheckConditions. This caused races on _conditionCheckFuture (called from both threads) and _helperThreads. This could happen if conditions / actions were marked to run in parallel to the main loop. --- lib/advanced-scene-switcher.cpp | 3 ++- lib/macro/macro-helpers.hpp | 3 ++- lib/macro/macro.cpp | 9 ++++++++- lib/macro/macro.hpp | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/advanced-scene-switcher.cpp b/lib/advanced-scene-switcher.cpp index b7b9fd64..19df94a4 100644 --- a/lib/advanced-scene-switcher.cpp +++ b/lib/advanced-scene-switcher.cpp @@ -461,12 +461,13 @@ void SwitcherData::Stop() SetMacroAbortWait(true); GetMacroWaitCV().notify_all(); GetMacroTransitionCV().notify_all(); - StopAllMacros(); + SignalStopAllMacros(); StopAndClearAllActionQueues(); CloseAllInputDialogs(); th->wait(); delete th; th = nullptr; + WaitForAllMacros(); RunStopSteps(); } diff --git a/lib/macro/macro-helpers.hpp b/lib/macro/macro-helpers.hpp index c31bc7e3..ae7da46a 100644 --- a/lib/macro/macro-helpers.hpp +++ b/lib/macro/macro-helpers.hpp @@ -76,7 +76,8 @@ EXPORT bool RunMacroElseActions(Macro *, bool forceParallel = false, bool ignorePause = false); EXPORT bool RunMacros(); -void StopAllMacros(); +void SignalStopAllMacros(); +void WaitForAllMacros(); EXPORT void LoadMacros(obs_data_t *obj); EXPORT void SaveMacros(obs_data_t *obj); diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index 7fe05fbf..c0000880 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -1316,7 +1316,14 @@ bool RunMacros() return true; } -void StopAllMacros() +void SignalStopAllMacros() +{ + for (const auto &m : GetAllMacros()) { + m->SignalStop(); + } +} + +void WaitForAllMacros() { for (const auto &m : GetAllMacros()) { m->Stop(); diff --git a/lib/macro/macro.hpp b/lib/macro/macro.hpp index 45433d12..1a8800db 100644 --- a/lib/macro/macro.hpp +++ b/lib/macro/macro.hpp @@ -61,6 +61,7 @@ public: PauseStateSaveBehavior GetPauseStateSaveBehavior() const; void Stop(); + void SignalStop() { _stop = true; } bool GetStop() const { return _stop; } void ResetTimers(); @@ -228,7 +229,7 @@ void LoadMacros(obs_data_t *obj); void SaveMacros(obs_data_t *obj); bool CheckMacros(); bool RunMacros(); -void StopAllMacros(); +void WaitForAllMacros(); void InvalidateMacroTempVarValues(); std::shared_ptr GetMacroWithInvalidConditionInterval();