From 9d2ffcc165a526e95b5b5f87ad77dff9b45f294d Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 8 Oct 2026 08:27:42 -0400 Subject: [PATCH] Standalone: never activate a plugin at sample rate 0 activatePlugin now refuses a non-positive sample rate or an empty block range. With no output device, a plugin that called request_restart was activated at 0 Hz on macOS. Both the macOS and Windows restart handlers now only reactivate a plugin that is currently active. Assisted-by: Claude Opus 5.5 --- src/detail/standalone/macos/AppDelegate.mm | 3 ++- src/detail/standalone/standalone_host.cpp | 7 +++++++ src/detail/standalone/windows/windows_standalone.cpp | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/detail/standalone/macos/AppDelegate.mm b/src/detail/standalone/macos/AppDelegate.mm index 97a37b35..2d208c06 100644 --- a/src/detail/standalone/macos/AppDelegate.mm +++ b/src/detail/standalone/macos/AppDelegate.mm @@ -36,7 +36,8 @@ - (void)timerCallback:(NSTimer *)instance plugin->on_main_thread(plugin); } - if (standaloneHost->restartRequested.exchange(false)) + // an inactive plugin has nothing to restart + if (standaloneHost->restartRequested.exchange(false) && standaloneHost->isActive) { // manually set running to false to make clapProcess a no-op // while the plugin is being reactivated. otherwise, diff --git a/src/detail/standalone/standalone_host.cpp b/src/detail/standalone/standalone_host.cpp index c2bf14b2..7ec917e1 100644 --- a/src/detail/standalone/standalone_host.cpp +++ b/src/detail/standalone/standalone_host.cpp @@ -603,6 +603,13 @@ bool StandaloneHost::activatePlugin(int32_t sr, int32_t minBlock, int32_t maxBlo { if (!clapPlugin) return false; + // no device has run yet, or none is attached + if (sr <= 0 || maxBlock < minBlock || minBlock < 1) + { + LOGINFO("[ERROR] Not activating with sampleRate={} blockBounds={} to {}", sr, minBlock, maxBlock); + return false; + } + deactivatePlugin(); LOGINFO("Activating plugin : sampleRate={} blockBounds={} to {}", sr, minBlock, maxBlock); diff --git a/src/detail/standalone/windows/windows_standalone.cpp b/src/detail/standalone/windows/windows_standalone.cpp index afdb1d04..e1a61ec4 100644 --- a/src/detail/standalone/windows/windows_standalone.cpp +++ b/src/detail/standalone/windows/windows_standalone.cpp @@ -1107,7 +1107,8 @@ Plugin::Plugin(std::shared_ptr clapPlugin, int nCmdShow) plugin.plugin->on_main_thread(plugin.plugin); } - if (sah->restartRequested.exchange(false)) + // an inactive plugin has nothing to restart + if (sah->restartRequested.exchange(false) && sah->isActive) { // Reactivate in place rather than bouncing the whole audio // engine. activatePlugin parks the callback, reactivates, and