LWJGL and XCB causes random crashes

Started by Aisaaax, February 12, 2020, 06:10:44

Previous topic - Next topic

Aisaaax

Hello.
I'm working on a 3d-render subsystem of a larger Embedded project, and I'm using LWJGL for that.
One of the problems that I ran into was that I need to somehow combine my work with Swing. Because the rest of the app is written heavily relying on it.
I solved that problem by having an AWT Canvas and rendering directly to it, by obtaining the XCB drawing surface and rendering directly to it.

And it seemed to have solved the problem. It works on my PC, and it also works on the embedded device that we're targeting.
However when we tried to merge my branch into the main project, an issue accourred. on some machines, for some reason XCB and XLib start crashing randomly and the app is unworkable.
All problems seem to be pointing to XCB and Multithreading. The error message itself suggests to use XInitThreads, but I couldn't find how to use it from LWJGL....

[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting...


What do I do? Is there any alternative?

Here's how I'm handling multithreading in my app:
public void lock() throws AWTException {
        int lock = JAWT_DrawingSurface_Lock(ds, ds.Lock());
        if ((lock & JAWT_LOCK_ERROR) != 0)
            throw new AWTException("JAWT_DrawingSurface_Lock() failed");
    }

    public void unlock() throws AWTException {
        JAWT_DrawingSurface_Unlock(ds, ds.Unlock());
    }


I'm calling Lock() before doing anything at all with the drawing surface and Unlock() right after. But I also suspect that Swing could do something to it or to the Canvas without me handling it - and I don't really know what can be done about it...

Aisaaax

I found a workaround
https://github.com/dunnololda/scage/blob/master/xdll.cpp

Basically you compile the .so file and pre-load it before running the jar.

But I still want to understand why it runs without this crutch on my PC. It runs on several cores in multiple threads and it's fine. And yet on another PC it just doesn't.
My project lead doesn't want any crutches and now just demands I figure out why it works on my end, as if I'm guilty of something... :P
Why COULD it work on one machine and not work on another, with exact same OS, Java version, drivers and even hardware?

The problem seems to be that none of LWJGL functions or AWT functions call the XInitThreads, and at the same time pre-compiled JNI modules that enable working with it do not expose the function.