SDL_DestroyWindow blocked infinitely by XIfEvent

Hi everyone!

I’m trying to use SDL to make UIs of audio plugins, because I want to use SDL’s cross-platform support for creating OpenGL context and event handling. The SDL-created window is attached to an existing window (provided by “host” program) using platform-specific APIs, i.e. XReparentWindow in Linux.

Currently I’m facing the problem that when it is going to destruct the UI, SDL_DestroyWindow is blocked by XIfEvent infinitely. I browsed the stack that blocks, the source code inside SDL_x11window.c is:

    if (X11_IsWindowMapped(_this, window)) {
        X11_XWithdrawWindow(display, data->xwindow, screen);
        // Blocking wait for "UnmapNotify" event
        if (!(window->flags & SDL_WINDOW_EXTERNAL) && X11_IsDisplayOk(display)) {
            X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow); // this is where it stucks
        }
        X11_XFlush(display);
    }

I’m not familiar with X11 programming, and I don’t know neither why it needs to wait for a UnmapNotify event, nor why it is blocked on the specific circumstances. So I ask here for help.

And here are some points:

  • I have ensured that all SDL and X11 code are called in one thread.
  • I use platform-specific XReparentWindow instead of SDL_SetWindowParent, because wrapping the existing parent window with SDL_CreateWindowWithProperties would disturb the behavior of the parent window.

Thanks for a lot!

What version of SDL are you using? I remember something like this being fixed for the latest release.

I’m using 3.2.28 which is a stable version. Should I try a newer testing version?

Yes, please try the 3.4.0 release?

If you’re able to reproduce it there, please report a bug and include your system information including your window manager:

I have fixed it. In Linux, JUCE triggers event in a separate thread. So previously I put window destruction into that thread, and it seems a too late time. Now I execute SDL window destruction instantly on audio plugin UI destruction, and everything works fine.

1 Like