We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1974 - X11 - X11_ShowWindow blocks on calling XIfEvent while creating a SDL_RENDERER_ACCERLATED renderer on a foregin window
Summary: X11 - X11_ShowWindow blocks on calling XIfEvent while creating a SDL_RENDERER...
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-14 23:22 UTC by miscab
Modified: 2013-07-28 14:25 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description miscab 2013-07-14 23:22:20 UTC
It's consecutive bug report of Bug 1526.

Platform: 32bit Ubuntu 12.04 under Vmware
SDL Version: SDL version 2.0.0 (stable)
Relevant files: SDL_x11window.c
Relevant functions: X11_ShowWindow, X11_HideWindow

Scenarios:

It's an QWidget window class and this->winId() will return the window handle of it. The program freezes after I called the following codes;

SDL_Window *window = SDL_CreateWindowFrom((void *)this->winId());   //OK
if(window == NULL)
{
    return;
}

SDL_Render *render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);  //WRONG, Freezing@!

When I followed in, I found that the program blocks at XIfEvent(display...

void
X11_HideWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    Display *display = data->videodata->display;
    XEvent event;

    if (X11_IsWindowMapped(_this, window)) {
        XUnmapWindow(display, data->xwindow);
        /* Blocking wait for "UnmapNotify" event */
        XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
        XFlush(display);
    }
}

then I applied the patch given by Bug 1526 patch, the code will look like:

void
X11_HideWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    Display *display = data->videodata->display;
    SDL_DisplayData *displaydata = 
	(SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    XEvent event;

    if (X11_IsWindowMapped(_this, window)) {
        //XUnmapWindow(display, data->xwindow);
        XWithdrawWindow(display, data->xwindow, displaydata->screen);
        /* Blocking wait for "UnmapNotify" event */
        XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
        XFlush(display);
    }
}

So far, the X11_HideWindow doesn't block anymore, however, the XIfEvent got freezing at X11_ShowWindow, the code is as below:

void X11_ShowWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    Display *display = data->videodata->display;
    XEvent event;

    if (!X11_IsWindowMapped(_this, window)) {
        XMapRaised(display, data->xwindow);
        /* Blocking wait for "MapNotify" event.
         * We use XIfEvent because XWindowEvent takes a mask rather than a type,
         * and XCheckTypedWindowEvent doesn't block */
        XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
        XFlush(display);
    }
}

Expected behavior: SDL_CreateRenderer return successfully
Observed behavior: program freezes forever.
Comment 1 miscab 2013-07-14 23:29:05 UTC
Everything is fine when Create a software render.
Comment 2 Sam Lantinga 2013-07-27 03:22:56 UTC
It looks like if the X window has a parent that is unmapped, XMapWindow() won't generate a MapNotify event.  Is that the case here?  If so, you should probably use Qt's window management functions.
Comment 3 miscab 2013-07-27 20:54:05 UTC
Sounds reasonable, so what I need do is to make the Qt parent window mapped?
I will try it and get back here, thank you, Sam.
(In reply to comment #2)
> It looks like if the X window has a parent that is unmapped, XMapWindow()
> won't generate a MapNotify event.  Is that the case here?  If so, you should
> probably use Qt's window management functions.
Comment 4 Sam Lantinga 2013-07-28 14:25:51 UTC
Yup, that sounds right to me.

Cheers!