fix: VST3 teardown under lock + re-attach hang + editor window on replace

- InstrumentEngineManager::assign: destroy replaced instrument OUTSIDE mu_
  (VST3 terminate/removed can block -> audio loop stall -> bridge Not
  Responding, transport stop hangs, notes never off)
- main.cpp LOAD job: DestroyWindow any open editor window of the channel
  before assign (replace VSTi -> SF2 with editor alive hung in removed())
- Vst3Instrument: reload() fresh plugin instance on second openGUI after
  close (Nexus etc. hang at view->attached() twice on same component)
This commit is contained in:
2026-08-13 12:48:30 +07:00
parent 3f59c2c4c2
commit c3eb0c9d16
4 changed files with 67 additions and 1 deletions
@@ -174,10 +174,18 @@ bool InstrumentEngineManager::assign(uint32_t channel, InstrumentType type,
// Replacing an existing instrument drops its voices with the old engine.
// Load may run on a detached thread (VST3 init is slow): only the map
// write is under the mutex so renderAll on the audio loop never stalls.
// CRITICAL: the OLD instrument is destroyed AFTER mu_ is released. VST3
// teardown (setProcessing(false) / terminate / view removed) can block;
// under the lock it would stall renderAll -> bridge Not Responding,
// transport stop hangs, notes never turn off (must kill daw_engine).
std::unique_ptr<INativeInstrument> oldInst;
{
std::lock_guard<std::mutex> lock(mu_);
auto it = channels_.find(channel);
if (it != channels_.end()) oldInst = std::move(it->second);
channels_[channel] = std::move(inst);
}
oldInst.reset();
return true;
}