From 09ee69b0ee8cd306a4fdf0a5e8641d6d013bbce7 Mon Sep 17 00:00:00 2001 From: defiantnerd <97224712+defiantnerd@users.noreply.github.com> Date: Wed, 30 Jul 2025 21:31:58 +0200 Subject: [PATCH 1/3] request resize must be in the main thread on VST3 Co-authored-by: Joseph Lyncheski Co-authored-by: Sam Windell --- src/wrapasvst3.cpp | 24 ++++++++++++++++++++++++ src/wrapasvst3.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 4fedd98e..7acd2fc8 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -12,6 +12,10 @@ #include #include +// we need this lock free since we can request a gui resize from any thread in CLAP +static_assert(std::atomic::is_always_lock_free, + "compiler must ensure that std::atomic is lock free"); + #if WIN #include #define S16(x) reinterpret_cast(_T(x)) @@ -1106,6 +1110,16 @@ bool ClapAsVst3::gui_can_resize() bool ClapAsVst3::gui_request_resize(uint32_t width, uint32_t height) { + // UIs with 65kx65k resolution are not supported + if ((width > 0xffff) && (height > 0xffff)) return false; + + if (_main_thread_id != std::this_thread::get_id()) + { + uint32_t newSize = ((width & 0xffff) << 16) | (height & 0xffff); + _gui_resize_request.store(newSize); + return true; + } + if (_wrappedview) return _wrappedview->request_resize(width, height); else @@ -1292,6 +1306,16 @@ void ClapAsVst3::onIdle() _plugin->_plugin->on_main_thread(_plugin->_plugin); } + if (_wrappedview) + { + if (auto const size = _gui_resize_request.exchange(_gui_invalid_size); size != _gui_invalid_size) + { + auto w = (size >> 16) & 0xffff; + auto h = (size & 0xffff); + _wrappedview->request_resize(w, h); + } + } + #if LIN if (!_iRunLoop) // don't process timers if we have a runloop. // (but if we don't have a runloop on linux onIdle isn't called diff --git a/src/wrapasvst3.h b/src/wrapasvst3.h index 6b5c9b2b..de0d4c09 100644 --- a/src/wrapasvst3.h +++ b/src/wrapasvst3.h @@ -40,6 +40,8 @@ #include "detail/vst3/aravst3.h" #include "detail/shared/spinlock.h" #include +#include +#include using namespace Steinberg; @@ -385,6 +387,11 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect, std::atomic_bool _requestUICallback = false; bool _missedLatencyRequest = false; + + std::thread::id _main_thread_id{}; + static const uint32_t _gui_invalid_size = 0xffffffff; + std::atomic _gui_resize_request = _gui_invalid_size; + // the queue from audiothread to UI thread ClapWrapper::detail::shared::fixedqueue _queueToUI; From 5642ab9f5b90bde78cbb3adef580f3f49ea07cba Mon Sep 17 00:00:00 2001 From: defiantnerd <97224712+defiantnerd@users.noreply.github.com> Date: Wed, 30 Jul 2025 21:36:13 +0200 Subject: [PATCH 2/3] clang-format --- src/wrapasvst3.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wrapasvst3.h b/src/wrapasvst3.h index de0d4c09..5587213e 100644 --- a/src/wrapasvst3.h +++ b/src/wrapasvst3.h @@ -387,12 +387,11 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect, std::atomic_bool _requestUICallback = false; bool _missedLatencyRequest = false; - + std::thread::id _main_thread_id{}; static const uint32_t _gui_invalid_size = 0xffffffff; std::atomic _gui_resize_request = _gui_invalid_size; - // the queue from audiothread to UI thread ClapWrapper::detail::shared::fixedqueue _queueToUI; From efc3e76e3d5dc40e2dd9aa1285dce203965659f0 Mon Sep 17 00:00:00 2001 From: defiantnerd <97224712+defiantnerd@users.noreply.github.com> Date: Wed, 30 Jul 2025 21:59:43 +0200 Subject: [PATCH 3/3] ||, not &&, of course --- src/wrapasvst3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 7acd2fc8..20c1e11d 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -1111,7 +1111,7 @@ bool ClapAsVst3::gui_can_resize() bool ClapAsVst3::gui_request_resize(uint32_t width, uint32_t height) { // UIs with 65kx65k resolution are not supported - if ((width > 0xffff) && (height > 0xffff)) return false; + if ((width > 0xffff) || (height > 0xffff)) return false; if (_main_thread_id != std::this_thread::get_id()) {