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); } //==============================================================================