Quellcode durchsuchen

Plugin windows: the editor's teardown runs inside the plugin guard

Crash reports since 0.1.31.2, group G4 (Cakewalk SI-* VST2: Vst2Editor::~Vst2Editor faults in the plugin's own window
code as its editor closes, 5 reports from one user): closing a plugin window deleted the editor outside the guard, so
the plugin's fault took LYNX down. The window's teardown now runs in crashguard::run, as onEditorFault's already did:
when the plugin faults, the window object is left behind, LYNX goes on, the session notes an editor crash (a later
unclean end offers the plugin a separate process) and plugin-crashes.log lists it. Test plugin: LYNX_TEST_CRASH=editorclose
("LYNX Test Crash.vst3" faults in IPlugView::removed); --plugwintest with it crashed 2 / 2 before, survives after. In 0.1.31.x.
Ka1-S vor 1 Woche
Ursprung
Commit
8d5be4db1e
2 geänderte Dateien mit 45 neuen und 5 gelöschten Zeilen
  1. 27 2
      src/ui/PluginWindow.cpp
  2. 18 3
      tools/testplugin/lynx_test_crash_vst3.cpp

+ 27 - 2
src/ui/PluginWindow.cpp

@@ -2280,10 +2280,35 @@ std::map<juce::AudioPluginInstance*, std::unique_ptr<EditorHost>>& windows()
     return open;
 }
 
+// Round 190rp (crash reports since 0.1.31.2, G4: Cakewalk SI-* VST2 editors fault in their own window code while the
+// editor closes, Vst2Editor::~Vst2Editor, 5 reports from one user): the editor window's teardown runs inside the plugin
+// guard (as onEditorFault's does). When the plugin faults there, the window object is left behind and LYNX goes on;
+// the session notes it as an editor crash (so a later unclean end offers the plugin a separate process) and
+// plugin-crashes.log lists it. The EditorHost keeps the plugin alive, so its name is read before.
+void destroyHost (const juce::AudioPluginInstance* key)
+{
+    auto& open = windows();
+    const auto it = open.find (const_cast<juce::AudioPluginInstance*> (key));
+    if (it == open.end())
+        return;
+    const auto name = it->first->getPluginDescription().name;
+    auto* raw = it->second.release();
+    open.erase (it);
+    if (const auto code = crashguard::run ([raw] { delete raw; }); code != 0)
+    {
+        crashguard::note ((juce::String (crashreport::editorCrashStepPrefix) + name + " (" + crashguard::describe (code)
+                           + " while its window closed): left behind")
+                              .toStdString());
+        PluginHost::settingsFolder().getChildFile ("plugin-crashes.log")
+            .appendText (juce::Time::getCurrentTime().toISO8601 (true) + "  " + name + "  editor close: " + crashguard::describe (code) + " 0x"
+                         + juce::String::toHexString ((juce::int64) code) + "\n");
+    }
+}
+
 void closeHostOf (const juce::AudioPluginInstance* plugin)
 {
     // close after leaving this callback (the window deletes itself)
-    juce::MessageManager::callAsync ([plugin] { windows().erase (const_cast<juce::AudioPluginInstance*> (plugin)); });
+    juce::MessageManager::callAsync ([plugin] { destroyHost (plugin); });
 }
 
 // Round 190ao, "Pin on top": pinned plugin windows stay above LYNX's other secondary windows. Like them they are owned by
@@ -2767,7 +2792,7 @@ bool isOpen (const juce::AudioPluginInstance& plugin)
 
 void close (const juce::AudioPluginInstance& plugin)
 {
-    windows().erase (const_cast<juce::AudioPluginInstance*> (&plugin));
+    destroyHost (&plugin); // (round 190rp: inside the plugin guard)
 }
 
 namespace

+ 18 - 3
tools/testplugin/lynx_test_crash_vst3.cpp

@@ -14,6 +14,10 @@
 //               handed out the editor window itself, deleted with the editor: the release went through freed memory
 //               (LYNX_TEST_CRASH=runloop LYNX --plugwintest "LYNX Test Crash.vst3" report.txt 2: the window opens, the
 //               plugin is removed, it must not crash)
+//   "editorclose" - (Linux; round 190rp) the same editor, but its IPlugView::removed() writes to a null pointer: a
+//               plugin that faults in its own window code while its editor closes (the Cakewalk SI-* VST2 crash reports,
+//               Vst2Editor::~Vst2Editor). LYNX_TEST_CRASH=editorclose LYNX --plugwintest "LYNX Test Crash.vst3" r.txt 2:
+//               LYNX must survive the editor's close (the teardown runs inside the plugin guard)
 //
 //   V=<JUCE>/modules/juce_audio_processors/format_types/VST3_SDK
 //   Linux:   B="LYNX Test Crash.vst3/Contents/x86_64-linux"; mkdir -p "$B"
@@ -321,7 +325,13 @@ public:
         return type != nullptr && std::strcmp (type, kPlatformTypeX11EmbedWindowID) == 0 ? kResultTrue : kResultFalse;
     }
     tresult PLUGIN_API attached (void*, FIDString) override { return kResultOk; }
-    tresult PLUGIN_API removed() override { return kResultOk; }
+    tresult PLUGIN_API removed() override
+    {
+        if (crashOnRemove)
+            *(volatile int*) nullptr = 1; // ("editorclose")
+        return kResultOk;
+    }
+    bool crashOnRemove = false;
     tresult PLUGIN_API onWheel (float) override { return kResultFalse; }
     tresult PLUGIN_API onKeyDown (char16, int16, int16) override { return kResultFalse; }
     tresult PLUGIN_API onKeyUp (char16, int16, int16) override { return kResultFalse; }
@@ -355,8 +365,13 @@ IPlugView* PLUGIN_API TestCrash::createView (FIDString name)
 #if defined(__linux__)
     char buffer[32];
     const auto* mode = environment ("LYNX_TEST_CRASH", buffer);
-    if (mode != nullptr && std::strcmp (mode, "runloop") == 0 && name != nullptr && std::strcmp (name, ViewType::kEditor) == 0)
-        return new RunLoopView (*this);
+    if (mode != nullptr && (std::strcmp (mode, "runloop") == 0 || std::strcmp (mode, "editorclose") == 0) && name != nullptr
+        && std::strcmp (name, ViewType::kEditor) == 0)
+    {
+        auto* view = new RunLoopView (*this);
+        view->crashOnRemove = std::strcmp (mode, "editorclose") == 0;
+        return view;
+    }
 #else
     (void) name;
 #endif