For anyone that has a bit more complex scenario and has multiple LookAndFeel classes to change the application theme - you need to set the used (by the components tree) L&F to nullptr on every change not only in the destructor and only after that to delete the old L&F.
Basically you need to detach it from the components and THEN delete it.
I’ve been debugging for 5h, now, so here is a little something to hopefully save someone some precious time:
// PluginEditor.h
class PluginEditor : public AudioProcessorEditor
{
//...
private:
ScopedPointer<LookAndFeel> lookAndFeel;
// ...
};
//==============================================================================
// PluginEditor.cpp
// ...
PluginEditor::~PluginEditor()
{
// if this is missing - YOU WILL HIT THE ASSERT
setLookAndFeel (nullptr);
// ...
}
// ...
void PluginEditor::selectTheme ()
{
// if this is missing - YOU WILL HIT THE ASSERT
setLookAndFeel (nullptr);
const String themeName = getThemeNameFromSomewhere ();
if (themeName == "X")
{
lookAndFeel = new LookAndFeel_X ();
}
else
{
lookAndFeel = new LookAndFeel_Y ();
}
setLookAndFeel (lookAndFeel);
}