G2.2: flush bridge state to disk before kill (control type=5 DUMP + Rust pre-kill)

This commit is contained in:
2026-08-16 07:52:01 +07:00
parent c2ae452844
commit d31312e824
4 changed files with 23 additions and 1 deletions
+18
View File
@@ -44,10 +44,26 @@ fn set_bridge_child(app: &AppHandle, child: Option<CommandChild>) {
}
}
/// G2.2: ask the bridge to flush its state file NOW (control type=5
/// DUMP_STATE), then give the UiThread save job ~300ms to finish before
/// the process is killed. Harmless when the bridge is already hung (SHM
/// is owned by Rust; the control is simply never consumed).
fn flush_bridge_state(app: &AppHandle) {
if let Some(state) = app.try_state::<ShmState>() {
if let Ok(guard) = state.0.lock() {
if let Some(shm) = guard.as_ref() {
let _ = shm.push_control(5, 0, 0, 0, "");
}
}
}
std::thread::sleep(std::time::Duration::from_millis(300));
}
/// Kill the currently managed bridge child (if any) — a restart MUST never
/// leave the old bridge running, else two daw_vst_bridge.exe race on the same
/// SHM (double instrument load, double OPEN_GUI, garbled control queue).
fn kill_bridge(app: &AppHandle) -> bool {
flush_bridge_state(app);
let state = app.state::<BridgeProcess>();
let mut guard = match state.0.lock() {
Ok(g) => g,
@@ -530,6 +546,8 @@ pub fn run() {
let _ = child.kill();
println!("daw_engine sidecar terminated.");
}
// G2.2: flush state to disk before killing the bridge
flush_bridge_state(window.app_handle());
// Terminate Native Host Bridge khi DAW window dong
let bridge_child = window
.state::<BridgeProcess>()