From 6db06f7a9a357570967d176da980b0c7167a0463 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 19 Oct 2017 11:58:50 +0100 Subject: [PATCH] Added an assertion that will be triggered at the moment you attempt to delete a LookAndFeel object that's still in use somewhere --- examples/Demo/Source/MainWindow.cpp | 6 ++++++ .../juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/examples/Demo/Source/MainWindow.cpp b/examples/Demo/Source/MainWindow.cpp index a8e79ba415..687807769a 100644 --- a/examples/Demo/Source/MainWindow.cpp +++ b/examples/Demo/Source/MainWindow.cpp @@ -126,6 +126,12 @@ public: addAndMakeVisible (demoList); } + ~ContentComponent() + { + // before deleting our lookandfeel object, make sure it's no longer in use + LookAndFeel::setDefaultLookAndFeel (nullptr); + } + void clearCurrentDemo() { currentDemo = nullptr; diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 11e9744434..3d2aed4dc9 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -50,6 +50,16 @@ LookAndFeel::LookAndFeel() LookAndFeel::~LookAndFeel() { + /* This assertion is triggered if you try to delete a LookAndFeel object while it's + - still being used as the default LookAndFeel; or + - is set as a Component's current lookandfeel; or + - pointed to by a WeakReference somewhere else in the code + + Deleting a LookAndFeel is unlikely to cause a crash since most things will use a + safe WeakReference to it, but it could cause some unexpected graphical behaviour, + so it's advisable to clear up any references before destroying them! + */ + jassert (masterReference.getNumActiveWeakReferences() == 0); } //==============================================================================