From fc64b13fe831739a7d16215f0843e7d02f0bac2b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 10 Apr 2024 21:41:29 -0400 Subject: [PATCH] Clear engine before instantiating modules and before locking in Engine::fromJson(). Fixes ParamHandles from being removed immediately after instantiated modules add them. --- src/engine/Engine.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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);