DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit d9044f27fe462d1827a8fcd2a2fa0bf988c0067f
parent 1ce0d89cc0625d25a92bf6f6c4ff3fd4ba404c33
Author: falkTX <falktx@falktx.com>
Date:   Sat,  2 Oct 2021 03:34:02 +0100

Prevent crashes when UI initializes too early

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/src/WindowPrivateData.cpp | 6+++++-
Mdistrho/src/DistrhoUIInternal.hpp | 2++
Mdistrho/src/DistrhoUIPrivateData.hpp | 12++++++++++++
Mdistrho/src/DistrhoUIVST3.cpp | 22+++++++++++-----------
4 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp @@ -33,7 +33,11 @@ #define DGL_DEBUG_EVENTS #if defined(DEBUG) && defined(DGL_DEBUG_EVENTS) -# include <cinttypes> +# ifdef DISTRHO_PROPER_CPP11_SUPPORT +# include <cinttypes> +# else +# include <inttypes.h> +# endif #endif START_NAMESPACE_DGL diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp @@ -99,6 +99,8 @@ public: DISTRHO_SAFE_ASSERT_RETURN(uiPtr != nullptr,); ui = uiPtr; + uiData->initializing = false; + #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI // unused (void)bundlePath; diff --git a/distrho/src/DistrhoUIPrivateData.hpp b/distrho/src/DistrhoUIPrivateData.hpp @@ -285,6 +285,7 @@ struct UI::PrivateData { void* dspPtr; // UI + bool initializing; uint bgColor; uint fgColor; double scaleFactor; @@ -308,6 +309,7 @@ struct UI::PrivateData { sampleRate(0), parameterOffset(0), dspPtr(nullptr), + initializing(true), bgColor(0), fgColor(0xffffffff), scaleFactor(1.0), @@ -358,30 +360,40 @@ struct UI::PrivateData { void editParamCallback(const uint32_t rindex, const bool started) { + DISTRHO_SAFE_ASSERT_RETURN(!initializing,); + if (editParamCallbackFunc != nullptr) editParamCallbackFunc(callbacksPtr, rindex, started); } void setParamCallback(const uint32_t rindex, const float value) { + DISTRHO_SAFE_ASSERT_RETURN(!initializing,); + if (setParamCallbackFunc != nullptr) setParamCallbackFunc(callbacksPtr, rindex, value); } void setStateCallback(const char* const key, const char* const value) { + DISTRHO_SAFE_ASSERT_RETURN(!initializing,); + if (setStateCallbackFunc != nullptr) setStateCallbackFunc(callbacksPtr, key, value); } void sendNoteCallback(const uint8_t channel, const uint8_t note, const uint8_t velocity) { + DISTRHO_SAFE_ASSERT_RETURN(!initializing,); + if (sendNoteCallbackFunc != nullptr) sendNoteCallbackFunc(callbacksPtr, channel, note, velocity); } void setSizeCallback(const uint width, const uint height) { + DISTRHO_SAFE_ASSERT_RETURN(!initializing,); + if (setSizeCallbackFunc != nullptr) setSizeCallbackFunc(callbacksPtr, width, height); } diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp @@ -486,17 +486,17 @@ private: DISTRHO_SAFE_ASSERT_RETURN(fFrame != nullptr,); d_stdout("from UI setSize %u %u | %p %p", width, height, fView, fFrame); -// #ifdef DISTRHO_OS_MAC -// const double scaleFactor = fUI.getScaleFactor(); -// width /= scaleFactor; -// height /= scaleFactor; -// #endif -// -// v3_view_rect rect; -// std::memset(&rect, 0, sizeof(rect)); -// rect.right = width; -// rect.bottom = height; -// v3_cpp_obj(fFrame)->resize_view(fFrame, fView, &rect); +#ifdef DISTRHO_OS_MAC + const double scaleFactor = fUI.getScaleFactor(); + width /= scaleFactor; + height /= scaleFactor; +#endif + + v3_view_rect rect; + std::memset(&rect, 0, sizeof(rect)); + rect.right = width; + rect.bottom = height; + v3_cpp_obj(fFrame)->resize_view(fFrame, fView, &rect); } static void setSizeCallback(void* ptr, uint width, uint height)