From 19ee32039b4adc4fd1851f069971b0a4b2f6f217 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 10 Oct 2022 17:38:57 +0200 Subject: [PATCH] Allow set_size() before set_parent() REAPER does this. --- src/wine-host/bridges/clap.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wine-host/bridges/clap.cpp b/src/wine-host/bridges/clap.cpp index abf41e4b..cd850b2c 100644 --- a/src/wine-host/bridges/clap.cpp +++ b/src/wine-host/bridges/clap.cpp @@ -514,22 +514,28 @@ void ClapBridge::run() { [&, plugin = instance.plugin.get(), gui = instance.extensions.gui, &editor = instance.editor]() { - assert(editor); - // HACK: We need to resize the editor window before // setting the size on the plugin. Surge XT and // presumably other CLAP JUCE Extensions plugins // will request a resize to the same size that was // just set. This causes a resize loop, so we'll // try to prevent resizes to the same size. - const Size old_size = editor->size(); - editor->resize(request.width, request.height); + // The host is allowed to call this before + // `set_parent()`, so the editor instance may not + // yet exist. + Size old_size{}; + if (editor) { + old_size = editor->size(); + editor->resize(request.width, request.height); + } if (gui->set_size(plugin, request.width, request.height)) { return true; } else { - editor->resize(old_size.width, old_size.height); + if (editor) { + editor->resize(old_size.width, old_size.height); + } return false; }