fix(audio): fail runDeviceLifecycleOp when the MessageManager is gone

A null MessageManager (pre-init or mid-shutdown) previously fell through
to inline execution on the caller's thread while reporting success -
exactly the unserialised device teardown this helper prevents. Return
false instead, per the documented unavailable/timeout contract.

Addresses CodeRabbit review on #113.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
OmikronApex
2026-07-16 22:54:22 +02:00
co-authored by Claude Fable 5
parent 354052bc7c
commit aa0bb9d173
+9 -3
View File
@@ -84,9 +84,15 @@ template <typename Func>
inline bool runDeviceLifecycleOp(Func&& func)
{
#if JUCE_WINDOWS
if (auto* mm = juce::MessageManager::getInstanceWithoutCreating())
if (!mm->isThisTheMessageThread())
return dispatchOnMessageThread(std::forward<Func>(func));
// No MessageManager means the pump is gone (pre-init or mid-shutdown):
// report failure instead of running the mutation unserialised on the
// caller's thread — that would reintroduce the race this helper exists
// to prevent (CodeRabbit #113 review).
auto* mm = juce::MessageManager::getInstanceWithoutCreating();
if (mm == nullptr)
return false;
if (!mm->isThisTheMessageThread())
return dispatchOnMessageThread(std::forward<Func>(func));
#endif
func();
return true;