From 5aaa500dc0a41dd46c736a2bf375fb397caefb26 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 4 Jan 2015 08:09:55 +0000 Subject: [PATCH] Properly wait for ui-bridges to get all messages, fixes #159 (I hope) --- source/backend/plugin/CarlaPluginLV2.cpp | 8 ++++++-- source/bridges-ui/CarlaBridgeUI.cpp | 18 +++++++++++++++--- source/bridges-ui/CarlaBridgeUI.hpp | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 7802bb42a..486e86462 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -1493,6 +1493,10 @@ public: break; } } + else + { + // TODO - detect if ui-bridge crashed + } if (fUI.handle != nullptr && fUI.descriptor != nullptr) { @@ -4461,7 +4465,7 @@ public: { CARLA_SAFE_ASSERT_RETURN(fUI.type == UI::TYPE_EMBED,); CARLA_SAFE_ASSERT_RETURN(fUI.window != nullptr,); - carla_stdout("CarlaPluginLV2::handlePluginUIResized(%u, %u)", width, height); + carla_debug("CarlaPluginLV2::handlePluginUIResized(%u, %u)", width, height); if (fUI.handle != nullptr && fExt.uiresize != nullptr) fExt.uiresize->ui_resize(fUI.handle, static_cast(width), static_cast(height)); @@ -5441,7 +5445,7 @@ public: { CARLA_SAFE_ASSERT_RETURN(urid != CARLA_URI_MAP_ID_NULL,); CARLA_SAFE_ASSERT_RETURN(uri != nullptr && uri[0] != '\0',); - carla_stdout("CarlaPluginLV2::handleUridMap(%i v " P_SIZE ", \"%s\")", urid, fCustomURIDs.count()-1, uri); + carla_debug("CarlaPluginLV2::handleUridMap(%i v " P_SIZE ", \"%s\")", urid, fCustomURIDs.count()-1, uri); if (urid < fCustomURIDs.count()) { diff --git a/source/bridges-ui/CarlaBridgeUI.cpp b/source/bridges-ui/CarlaBridgeUI.cpp index 596e54401..8b64ea1d6 100644 --- a/source/bridges-ui/CarlaBridgeUI.cpp +++ b/source/bridges-ui/CarlaBridgeUI.cpp @@ -32,6 +32,7 @@ CarlaBridgeUI::CarlaBridgeUI() noexcept : CarlaPipeClient(), fQuitReceived(false), fGotOptions(false), + fLastMsgTimer(-1), fToolkit(nullptr), fLib(nullptr), fLibFilename(), @@ -112,6 +113,9 @@ bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept CARLA_SAFE_ASSERT_RETURN(std::strcmp(msg, "urid") == 0 || std::strcmp(msg, "uiOptions") == 0, true); } + if (fLastMsgTimer > 0) + --fLastMsgTimer; + if (std::strcmp(msg, "control") == 0) { uint32_t index; @@ -284,15 +288,23 @@ bool CarlaBridgeUI::init(const int argc, const char* argv[]) if (! initPipeClient(argv)) return false; - // wait for ui options, FIXME - for (int i=0; i<20 && ! fGotOptions; ++i) + fLastMsgTimer = 0; + + // wait for ui options + for (; ++fLastMsgTimer < 50 && ! fGotOptions;) { idlePipe(true); - carla_msleep(100); + carla_msleep(20); } if (! fGotOptions) { + carla_stderr2("CarlaBridgeUI::init() - did not get options on time, quitting..."); + { + const CarlaMutexLocker cml(getPipeLock()); + writeMessage("exiting\n", 8); + flushMessages(); + } closePipeClient(); return false; } diff --git a/source/bridges-ui/CarlaBridgeUI.hpp b/source/bridges-ui/CarlaBridgeUI.hpp index 4b4bf4137..9e7e8c1b7 100644 --- a/source/bridges-ui/CarlaBridgeUI.hpp +++ b/source/bridges-ui/CarlaBridgeUI.hpp @@ -142,6 +142,7 @@ public: protected: bool fQuitReceived; bool fGotOptions; + int fLastMsgTimer; CarlaBridgeToolkit* fToolkit; lib_t fLib;