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
+37 -1
View File
@@ -169,7 +169,8 @@ Vst3Instrument::Vst3Instrument()
sampleRate_(44100.0),
maxBlockSize_(256),
loaded_(false),
guiAttached_(false) {}
guiAttached_(false),
hasAttachedOnce_(false) {}
Vst3Instrument::~Vst3Instrument() {
#ifdef HAVE_VST3SDK
@@ -489,6 +490,15 @@ bool Vst3Instrument::openGUI(void* parentWindowHandle) {
<< " controller=" << (s ? (s->controller ? 1 : 0) : -1) << std::endl;
if (!s || !s->controller || !parentWindowHandle) return false;
if (s->view && guiAttached_) return true;
if (hasAttachedOnce_ && !guiAttached_) {
// Reopen GUI sau khi dong: mot so plugin (Nexus...) hang o
// view->attached() LAN 2 tren cung component instance. Tao lai inst
// moi tren CUNG worker thread (COM STA con song) roi attach lai.
std::cerr << "[dbg] openGUI: re-attach - reloading fresh plugin instance" << std::endl;
if (!reload()) return false;
s = static_cast<Vst3HostState*>(state_);
if (!s || !s->controller) return false;
}
IPlugView* rawView = nullptr;
tresult qi = s->controller->queryInterface(IPlugView::iid, (void**)&rawView);
{
@@ -539,6 +549,7 @@ bool Vst3Instrument::openGUI(void* parentWindowHandle) {
#endif
s->view = view;
guiAttached_ = true;
hasAttachedOnce_ = true;
// ponytail: the bridge loop is a worker thread without a Windows message
// pump — some editors may not repaint until the first native event; a
// future version can spin a dedicated UI thread + pump.
@@ -546,6 +557,31 @@ bool Vst3Instrument::openGUI(void* parentWindowHandle) {
#endif
}
bool Vst3Instrument::reload() {
#ifndef HAVE_VST3SDK
return false;
#else
if (!state_) return false;
closeGUI();
auto* s = static_cast<Vst3HostState*>(state_);
if (s->component) {
FUnknownPtr<IAudioProcessor> processor(s->component);
if (processor) processor->setProcessing(false);
s->component->setActive(false);
s->component->terminate();
}
// Single-component plugins: controller == component, already terminated.
if (s->controller && !s->controllerIsComponent) s->controller->terminate();
s->processData.unprepare();
delete s;
state_ = nullptr;
loaded_ = false;
guiAttached_ = false;
hasAttachedOnce_ = false;
return loadPlugin(path_, sampleRate_);
#endif
}
void Vst3Instrument::closeGUI() {
#ifndef HAVE_VST3SDK
return;