From fd74f1a39d01d1664e3fba8fe199511ee2338501 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 22 Jun 2015 16:22:50 +0100 Subject: [PATCH] Changed the way the JUCE_LIVE_CONSTANT singletons are generated, to make it more robust when used in a plugin environment --- .../misc/juce_LiveConstantEditor.cpp | 30 ++++++++----------- .../misc/juce_LiveConstantEditor.h | 4 +-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index a091587625..3c85254bb2 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -32,13 +32,10 @@ class AllComponentRepainter : private Timer, private DeletedAtShutdown { public: - AllComponentRepainter() {} + AllComponentRepainter() {} + ~AllComponentRepainter() { clearSingletonInstance(); } - static AllComponentRepainter& getInstance() - { - static AllComponentRepainter* instance = new AllComponentRepainter(); - return *instance; - } + juce_DeclareSingleton (AllComponentRepainter, false) void trigger() { @@ -57,8 +54,10 @@ private: if (Component* c = TopLevelWindow::getTopLevelWindow(i)) repaintAndResizeAllComps (c, alreadyDone); - for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;) - if (Component* c = Desktop::getInstance().getComponent(i)) + Desktop& desktop = Desktop::getInstance(); + + for (int i = desktop.getNumComponents(); --i >= 0;) + if (Component* c = desktop.getComponent(i)) repaintAndResizeAllComps (c, alreadyDone); } @@ -85,6 +84,9 @@ private: } }; +juce_ImplementSingleton (AllComponentRepainter) +juce_ImplementSingleton (ValueList) + //============================================================================== int64 parseInt (String s) { @@ -189,7 +191,7 @@ void LivePropertyEditorBase::applyNewValue (const String& s) selectOriginalValue(); valueEditor.setText (s, dontSendNotification); - AllComponentRepainter::getInstance().trigger(); + AllComponentRepainter::getInstance()->trigger(); } void LivePropertyEditorBase::selectOriginalValue() @@ -347,14 +349,8 @@ public: }; //============================================================================== -ValueList::ValueList() {} -ValueList::~ValueList() {} - -ValueList& ValueList::getInstance() -{ - static ValueList* i = new ValueList(); - return *i; -} +ValueList::ValueList() {} +ValueList::~ValueList() { clearSingletonInstance(); } void ValueList::addValue (LiveValueBase* v) { diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h index 44c312cd19..5801ba2fdf 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -194,7 +194,7 @@ namespace LiveConstantEditor ValueList(); ~ValueList(); - static ValueList& getInstance(); + juce_DeclareSingleton (ValueList, false) template LiveValue& getValue (const char* file, int line, const Type& initialValue) @@ -233,7 +233,7 @@ namespace LiveConstantEditor template inline LiveValue& getValue (const char* file, int line, const Type& initialValue) { - return ValueList::getInstance().getValue (file, line, initialValue); + return ValueList::getInstance()->getValue (file, line, initialValue); } inline LiveValue& getValue (const char* file, int line, const char* initialValue)