diff --git a/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp b/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp index 1b80d8695d..ebc0bcdccb 100644 --- a/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp +++ b/extras/Projucer/Source/Project/Modules/jucer_Modules.cpp @@ -411,6 +411,8 @@ void EnabledModulesList::sortAlphabetically() }; ModuleTreeSorter sorter; + + const ScopedLock sl (stateLock); state.sort (sorter, getUndoManager(), false); } @@ -439,6 +441,7 @@ ModuleDescription EnabledModulesList::getModuleInfo (const String& moduleID) con bool EnabledModulesList::isModuleEnabled (const String& moduleID) const { + const ScopedLock sl (stateLock); return state.getChildWithProperty (Ids::ID, moduleID).isValid(); } @@ -502,11 +505,13 @@ bool EnabledModulesList::doesModuleHaveHigherCppStandardThanProject (const Strin bool EnabledModulesList::shouldUseGlobalPath (const String& moduleID) const { + const ScopedLock sl (stateLock); return (bool) shouldUseGlobalPathValue (moduleID).getValue(); } Value EnabledModulesList::shouldUseGlobalPathValue (const String& moduleID) const { + const ScopedLock sl (stateLock); return state.getChildWithProperty (Ids::ID, moduleID) .getPropertyAsValue (Ids::useGlobalPath, getUndoManager()); } @@ -518,6 +523,7 @@ bool EnabledModulesList::shouldShowAllModuleFilesInProject (const String& module Value EnabledModulesList::shouldShowAllModuleFilesInProjectValue (const String& moduleID) const { + const ScopedLock sl (stateLock); return state.getChildWithProperty (Ids::ID, moduleID) .getPropertyAsValue (Ids::showAllCode, getUndoManager()); } @@ -529,6 +535,7 @@ bool EnabledModulesList::shouldCopyModuleFilesLocally (const String& moduleID) c Value EnabledModulesList::shouldCopyModuleFilesLocallyValue (const String& moduleID) const { + const ScopedLock sl (stateLock); return state.getChildWithProperty (Ids::ID, moduleID) .getPropertyAsValue (Ids::useLocalCopy, getUndoManager()); } @@ -616,7 +623,11 @@ void EnabledModulesList::addModule (const File& moduleFolder, bool copyLocally, ValueTree module (Ids::MODULE); module.setProperty (Ids::ID, moduleID, getUndoManager()); - state.appendChild (module, getUndoManager()); + { + const ScopedLock sl (stateLock); + state.appendChild (module, getUndoManager()); + } + sortAlphabetically(); shouldShowAllModuleFilesInProjectValue (moduleID) = true; @@ -686,9 +697,13 @@ void EnabledModulesList::addModuleOfferingToCopy (const File& f, bool isFromUser void EnabledModulesList::removeModule (String moduleID) // must be pass-by-value, and not a const ref! { - for (auto i = state.getNumChildren(); --i >= 0;) - if (state.getChild(i) [Ids::ID] == moduleID) - state.removeChild (i, getUndoManager()); + { + const ScopedLock sl (stateLock); + + for (auto i = state.getNumChildren(); --i >= 0;) + if (state.getChild(i) [Ids::ID] == moduleID) + state.removeChild (i, getUndoManager()); + } for (Project::ExporterIterator exporter (project); exporter.next();) exporter->removePathForModule (moduleID); diff --git a/extras/Projucer/Source/Project/Modules/jucer_Modules.h b/extras/Projucer/Source/Project/Modules/jucer_Modules.h index 8d3e54bceb..c75272bc3e 100644 --- a/extras/Projucer/Source/Project/Modules/jucer_Modules.h +++ b/extras/Projucer/Source/Project/Modules/jucer_Modules.h @@ -138,6 +138,8 @@ private: UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); } Project& project; + + CriticalSection stateLock; ValueTree state; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EnabledModulesList)