| @@ -515,6 +515,13 @@ void Engine::step(int frames) { | |||||
| void Engine::setPrimaryModule(Module* module) { | void Engine::setPrimaryModule(Module* module) { | ||||
| SharedLock lock(internal->mutex); | SharedLock lock(internal->mutex); | ||||
| // Don't allow module to be set if not added to the Engine. | |||||
| // NULL will unset the primary module. | |||||
| if (module) { | |||||
| auto it = std::find(internal->modules.begin(), internal->modules.end(), module); | |||||
| if (it == internal->modules.end()) | |||||
| return; | |||||
| } | |||||
| internal->primaryModule = module; | internal->primaryModule = module; | ||||
| } | } | ||||
| @@ -1032,7 +1039,7 @@ json_t* Engine::toJson() { | |||||
| void Engine::fromJson(json_t* rootJ) { | void Engine::fromJson(json_t* rootJ) { | ||||
| // We can't lock here because addModule() and addCable() are called inside. | // We can't lock here because addModule() and addCable() are called inside. | ||||
| // Also, AudioInterface::fromJson() might call Engine::step() due to RtAudio drivers. | |||||
| // Also, AudioInterface::fromJson() can open the audio device, which can call Engine::step() before this method exits. | |||||
| // ExclusiveSharedLock lock(internal->mutex); | // ExclusiveSharedLock lock(internal->mutex); | ||||
| clear(); | clear(); | ||||
| // modules | // modules | ||||
| @@ -1054,7 +1061,7 @@ void Engine::fromJson(json_t* rootJ) { | |||||
| module->id = moduleIndex; | module->id = moduleIndex; | ||||
| } | } | ||||
| // This method locks | |||||
| // This method exclusively locks | |||||
| addModule(module); | addModule(module); | ||||
| } | } | ||||
| catch (Exception& e) { | catch (Exception& e) { | ||||
| @@ -1076,7 +1083,7 @@ void Engine::fromJson(json_t* rootJ) { | |||||
| Cable* cable = new Cable; | Cable* cable = new Cable; | ||||
| try { | try { | ||||
| cable->fromJson(cableJ); | cable->fromJson(cableJ); | ||||
| // This method locks | |||||
| // This method exclusively locks | |||||
| addCable(cable); | addCable(cable); | ||||
| } | } | ||||
| catch (Exception& e) { | catch (Exception& e) { | ||||