From 132295bdb3b3c6e5c5068f02338ac11c44547e0f Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 3 Apr 2019 15:13:02 +0100 Subject: [PATCH] Made the logMessage() method in UnitTestsDemo thread-safe --- examples/Utilities/UnitTestsDemo.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/Utilities/UnitTestsDemo.h b/examples/Utilities/UnitTestsDemo.h index 26b4dbc961..b74884c347 100644 --- a/examples/Utilities/UnitTestsDemo.h +++ b/examples/Utilities/UnitTestsDemo.h @@ -171,10 +171,13 @@ private: void logMessage (const String& message) { - MessageManagerLock mm (this); + WeakReference safeOwner (&owner); - if (mm.lockWasGained()) // this lock may fail if this thread has been told to stop - owner.logMessage (message); + MessageManager::callAsync ([=] + { + if (auto* o = safeOwner.get()) + o->logMessage (message); + }); } void timerCallback() override @@ -224,5 +227,6 @@ private: testResultsBox.applyFontToAllText (testResultsBox.getFont()); } + JUCE_DECLARE_WEAK_REFERENCEABLE (UnitTestsDemo) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UnitTestsDemo) };