Shut plugin hosting down in on_exit: ⌘Q exits from inside the event loop

The system Quit (⌘Q, or a quit Apple Event) goes through
-[NSApplication terminate:], which calls exit() from inside the event loop, so
eframe::run_native never returns and the shutdown placed after it never ran.
With HALion Sonic in use, the exit handler then ran its bundleExit too late and
the app crashed on quit ("quit unexpectedly", found in manual testing).

eframe calls on_exit on every way out, so the app now releases its player (and
with it the plugin instances) and shuts plugin hosting down there.

Refs #16

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ebbicott 2026-10-08 15:13:39 -04:00
parent ccd1f995bf
commit ae2362752c
1 changed files with 6 additions and 5 deletions

View File

@ -39,6 +39,10 @@ impl eframe::App for App {
}
fn on_exit(&mut self) {
save_prefs(&self.0.ui);
// The system Quit (⌘Q) ends the process from inside the event loop, so `run_native` never
// returns: release the player's plugin instances and shut plugin hosting down here.
self.0.player = None;
soundcraft_engine::shutdown_plugin_hosts();
}
}
@ -168,7 +172,7 @@ fn main() -> eframe::Result {
if let Some(icon) = app_icon() {
options.viewport = options.viewport.with_icon(icon);
}
let result = eframe::run_native(
eframe::run_native(
"SoundCraft",
options,
Box::new(move |cc| {
@ -188,8 +192,5 @@ fn main() -> eframe::Result {
}
Ok(Box::new(App(app)))
}),
);
// The app, its player and their plugin instances are gone once the event loop returns.
soundcraft_engine::shutdown_plugin_hosts();
result
)
}