diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index 8173ce9e8..302f45739 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -578,7 +578,7 @@ public: CARLA_SAFE_ASSERT_BREAK(data != nullptr); CarlaString dataBase64 = CarlaString::asBase64(data, dataSize); - CARLA_SAFE_ASSERT_RETURN(dataBase64.length() > 0,); + CARLA_SAFE_ASSERT_BREAK(dataBase64.length() > 0); String filePath(File::getSpecialLocation(File::tempDirectory).getFullPathName()); @@ -651,6 +651,7 @@ public: case kPluginBridgeNonRtQuit: signalThreadShouldExit(); + callback(ENGINE_CALLBACK_QUIT, 0, 0, 0, 0.0f, nullptr); break; } } @@ -868,6 +869,10 @@ protected: break; } + + case kPluginBridgeRtQuit: + signalThreadShouldExit(); + break; } } diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index 041926c15..aaaa54e50 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -383,6 +383,9 @@ public: fShmNonRtControl.writeOpcode(kPluginBridgeNonRtQuit); fShmNonRtControl.commitWrite(); + fShmRtControl.writeOpcode(kPluginBridgeRtQuit); + fShmRtControl.commitWrite(); + if (! fTimedOut) fShmRtControl.waitForServer(3); } diff --git a/source/backend/plugin/CarlaPluginThread.cpp b/source/backend/plugin/CarlaPluginThread.cpp index 96cc98535..460cf3f45 100644 --- a/source/backend/plugin/CarlaPluginThread.cpp +++ b/source/backend/plugin/CarlaPluginThread.cpp @@ -274,7 +274,7 @@ void CarlaPluginThread::run() // we only get here if UI was closed or thread asked to exit if (fProcess->isRunning() && shouldThreadExit()) { - //fProcess->waitForFinished(static_cast(fEngine->getOptions().uiBridgesTimeout)); + fProcess->waitForProcessToFinish(static_cast(fEngine->getOptions().uiBridgesTimeout)); if (fProcess->isRunning()) { @@ -309,12 +309,19 @@ void CarlaPluginThread::run() carla_sleep(1); // we only get here if bridge crashed or thread asked to exit - if (shouldThreadExit()) + if (fProcess->isRunning() && shouldThreadExit()) { - fProcess->getExitCode(); // TEST + fProcess->waitForProcessToFinish(2000); if (fProcess->isRunning()) + { + carla_stdout("CarlaPluginThread::run() - bridge refused to close, force kill now"); fProcess->kill(); + } + else + { + carla_stdout("CarlaPluginThread::run() - bridge auto-closed successfully"); + } } else { diff --git a/source/bridges-plugin/CarlaBridgePlugin.cpp b/source/bridges-plugin/CarlaBridgePlugin.cpp index 710c63c63..e6eda4726 100644 --- a/source/bridges-plugin/CarlaBridgePlugin.cpp +++ b/source/bridges-plugin/CarlaBridgePlugin.cpp @@ -325,6 +325,7 @@ protected: { case ENGINE_CALLBACK_ENGINE_STOPPED: case ENGINE_CALLBACK_PLUGIN_REMOVED: + case ENGINE_CALLBACK_QUIT: gCloseNow = true; break; diff --git a/source/utils/CarlaBridgeUtils.hpp b/source/utils/CarlaBridgeUtils.hpp index 721b986d2..e77cbf188 100644 --- a/source/utils/CarlaBridgeUtils.hpp +++ b/source/utils/CarlaBridgeUtils.hpp @@ -61,7 +61,8 @@ enum PluginBridgeRtOpcode { kPluginBridgeRtControlEventAllSoundOff, // uint/frame, byte/chan kPluginBridgeRtControlEventAllNotesOff, // uint/frame, byte/chan kPluginBridgeRtMidiEvent, // uint/frame, byte/port, byte/size, byte[]/data - kPluginBridgeRtProcess + kPluginBridgeRtProcess, + kPluginBridgeRtQuit }; // carla-plugin sends these during non-RT @@ -221,6 +222,8 @@ const char* PluginBridgeRtOpcode2str(const PluginBridgeRtOpcode opcode) noexcept return "kPluginBridgeRtMidiEvent"; case kPluginBridgeRtProcess: return "kPluginBridgeRtProcess"; + case kPluginBridgeRtQuit: + return "kPluginBridgeRtQuit"; } carla_stderr("CarlaBackend::PluginBridgeRtOpcode2str(%i) - invalid opcode", opcode);