DISTRHO / DISTRHO-Ports

Linux audio plugins and LV2 ports
http://distrho.sourceforge.net/ports
249 stars 44 forks source link

VST2 in reaper: Vitalium Crash on close/reopen #109

Open nidefawl opened 2 years ago

nidefawl commented 2 years ago

When reopening or sometimes even when having Vitalium in the background I get a segfault. I get the same crash inside my own DAW project. Apparently, after the window is closed, (or before it is fully opened?!) it keeps processing something on the event queue related to the parent window the VST2 implementation is passing to the plugin. It always crashes here (inside dynamic_cast): https://github.com/DISTRHO/DISTRHO-Ports/blob/5907a18cb50dd63d84d37776dfd8e8dcc7f3e378/libs/juce-current/source/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp#L3680

I tested the LV2 version on Reaper, and it doesn't seem to be affected.

Here is a workaround I came up with:

diff --git a/libs/juce-current/source/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp b/libs/juce-current/source/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
index 55e2bf2d..e9d37966 100644
--- a/libs/juce-current/source/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
+++ b/libs/juce-current/source/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
@@ -1388,7 +1388,9 @@ ComponentPeer* getPeerFor (::Window windowH)
     if (auto* display = XWindowSystem::getInstance()->getDisplay())
     {
         XWindowSystemUtilities::ScopedXLock xLock;
-        X11Symbols::getInstance()->xFindContext (display, (XID) windowH, windowHandleXContext, &peer);
+        if (!X11Symbols::getInstance()->xFindContext (display, (XID) windowH, windowHandleXContext, &peer))
+            if (peer != nullptr && ! ComponentPeer::isValidPeer (reinterpret_cast<LinuxComponentPeer*> (peer)))
+                peer = nullptr;
     }

     return unalignedPointerCast<ComponentPeer*> (peer);
@@ -2822,7 +2824,7 @@ void XWindowSystem::setWindowType (::Window windowH, int styleFlags) const
         std::vector<Atom> netStateHints;

         addAtomIfExists ((styleFlags & ComponentPeer::windowAppearsOnTaskbar) == 0, "_NET_WM_STATE_SKIP_TASKBAR", display, netStateHints);
-        addAtomIfExists (getPeerFor (windowH)->getComponent().isAlwaysOnTop(),      "_NET_WM_STATE_ABOVE",        display, netStateHints);
+        // addAtomIfExists (getPeerFor (windowH)->getComponent().isAlwaysOnTop(),      "_NET_WM_STATE_ABOVE",        display, netStateHints);

         auto numHints = (int) netStateHints.size();

BTW: I got crashes from the latest official Vital VST2 linux build at the very same location, so I think this workaround would help upstream as well.

nidefawl commented 2 years ago

Oh, it seems like this was fixed before, but deemed no longer necessary. 🤨

CameronAsselin commented 1 year ago

Having the same issue with the VST3 on Arch in Reaper.

The LV2 kept changing settings on a close/reopen and the VST3 fixed that, but eventually crashed Reaper and wont re-open the project file without crashing.