diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 68b1c09c..b01cbcf1 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -1215,7 +1215,11 @@ json_t* Engine::toJson() { void Engine::fromJson(json_t* rootJ) { + clear(); + // modules + // We can't instantiate modules before clearing because some modules add ParamHandles upon construction. + // We also can't lock while instantiating modules because they call addParamHandle() which locks. std::vector modules; json_t* modulesJ = json_object_get(rootJ, "modules"); if (!modulesJ) @@ -1257,8 +1261,6 @@ void Engine::fromJson(json_t* rootJ) { std::lock_guard lock(internal->mutex); - clear_NoLock(); - // Add modules for (Module* module : modules) { addModule_NoLock(module);