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
+20
View File
@@ -299,6 +299,26 @@ int main(int argc, char* argv[]) {
uint32_t ch = c.channel & 0xF;
if (!workers[ch]) workers[ch] = std::make_unique<ChannelWorker>();
workers[ch]->post([&instruments, t, ch, path, sampleRate, block]() {
#ifdef _WIN32
// DONG cua so editor dang mo cua channel TRUOC khi assign():
// thay the inst (VST3 -> SF2/inst khac) ma editor con song ->
// old inst destructor goi view->removed() tren HWND con hoat
// dong -> plugin block -> treo bridge. DestroyWindow chay tren
// CUNG worker thread so huu window; WM_DESTROY goi closeGUI()
// dung thu tu. Phai erase map TRUOC DestroyWindow (WM_DESTROY
// handler lay g_guiMutex lai — khong duoc giu lock khi destroy).
HWND hToDestroy = nullptr;
{
std::lock_guard<std::mutex> lock(g_guiMutex);
auto git = g_guiWindows.find(ch);
if (git != g_guiWindows.end()) {
hToDestroy = (HWND)git->second;
g_guiWindows.erase(git);
g_hwndToCh.erase(hToDestroy);
}
}
if (hToDestroy && IsWindow(hToDestroy)) DestroyWindow(hToDestroy);
#endif
std::cerr << "[dbg] load thread start ch=" << ch
<< " type=" << (int)t << " path=" << path << std::endl;
bool ok = instruments.assign(ch, t, path, sampleRate, block);