Linux VST + OpenGL crash because XInitThreads not called

My plugin with an attached openGL context crashes when loaded into a DAW on Linux.

This is “fixed” with a call to XInitThreads in MessageManager::doPlatformSpecificInitialisation() in modules/juce_events/native/juce_linux_Messaging.cpp

However, looking into the XInitThreads documentation, I’m guessing it should have been called from the DAW. I’ve tested in Bitwig and Ardour and they both crash with the standard behavior but they work with the call to XInitThreads. I do have to call XInitThreads every call to doPlatformSpecificInitialisation and haven’t seen any crashes from calling XInitThreads too late, so it’s possible this is the correct usage.

Here’s my “fix” that replaces the first part of MessageManager::doPlatformSpecificInitialisation:

// Initialise xlib for multiple thread support
static bool standaloneInitThreadCalled = false;
if (!JUCEApplicationBase::isStandaloneApp() || !standaloneInitThreadCalled)
{
    if (! XInitThreads())
    {
        // This is fatal!  Print error and closedown
        Logger::outputDebugString ("Failed to initialise xlib thread support.");
        Process::terminate();
        return;
    }

    standaloneInitThreadCalled = true;

    LinuxErrorHandling::installXErrorHandlers();
    LinuxErrorHandling::installKeyboardBreakHandler();
}

A fix for this will appear on develop in a few moments.

1 Like

Thank you so much!

I didn’t see the fix on the develop branch. Did I miss it?

Just checking in on this.

Sorry, pushing to a wrong branch and then going on holiday is a really bad combination.

It’s on develop now with this commit.

No probs, thanks!