From f28e6fcce8ca01983cd89701c87a606bb4fc725d Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 6 Sep 2018 08:56:42 +0200 Subject: [PATCH] Fix lv2-ui-bridge crash when it expects a window title Fixes #719 --- source/bridges-ui/CarlaBridgeFormatLV2.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/source/bridges-ui/CarlaBridgeFormatLV2.cpp b/source/bridges-ui/CarlaBridgeFormatLV2.cpp index 81807c8a4..79a776245 100644 --- a/source/bridges-ui/CarlaBridgeFormatLV2.cpp +++ b/source/bridges-ui/CarlaBridgeFormatLV2.cpp @@ -37,6 +37,9 @@ CARLA_BRIDGE_UI_START_NAMESPACE // -------------------------------------------------------------------------------------------------------------------- static double gInitialSampleRate = 44100.0; +static const char* const kNullWindowTitle = "TestUI"; +static const uint32_t kNullWindowTitleSize = 6; + // LV2 URI Map Ids enum CarlaLv2URIDs { @@ -136,7 +139,7 @@ struct Lv2PluginOptions { Lv2PluginOptions() noexcept : sampleRate(gInitialSampleRate), transientWinId(0), - windowTitle(nullptr) + windowTitle(kNullWindowTitle) { LV2_Options_Option& optSampleRate(opts[SampleRate]); optSampleRate.context = LV2_OPTIONS_INSTANCE; @@ -158,9 +161,9 @@ struct Lv2PluginOptions { optWindowTitle.context = LV2_OPTIONS_INSTANCE; optWindowTitle.subject = 0; optWindowTitle.key = kUridWindowTitle; - optWindowTitle.size = 0; + optWindowTitle.size = kNullWindowTitleSize; optWindowTitle.type = kUridAtomString; - optWindowTitle.value = nullptr; + optWindowTitle.value = kNullWindowTitle; LV2_Options_Option& optNull(opts[Null]); optNull.context = LV2_OPTIONS_INSTANCE; @@ -598,13 +601,22 @@ public: } } - delete[] fLv2Options.windowTitle; + if (fLv2Options.windowTitle != nullptr && fLv2Options.windowTitle != kNullWindowTitle) + delete[] fLv2Options.windowTitle; + fLv2Options.transientWinId = static_cast(transientWindowId); fLv2Options.windowTitle = carla_strdup_safe(windowTitle); + if (fLv2Options.windowTitle == nullptr) + fLv2Options.windowTitle = kNullWindowTitle; + else + fUiOptions.windowTitle = fLv2Options.windowTitle; + + fLv2Options.opts[Lv2PluginOptions::WindowTitle].size = (uint32_t)std::strlen(fLv2Options.windowTitle); + fLv2Options.opts[Lv2PluginOptions::WindowTitle].value = fLv2Options.windowTitle; + fUiOptions.useTheme = useTheme; fUiOptions.useThemeColors = useThemeColors; - fUiOptions.windowTitle = fLv2Options.windowTitle; fUiOptions.transientWindowId = transientWindowId; }