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 2154

Summary: X11: Crash in ' SDL_ShowSimpleMessageBox()' since commit d4a39491577f
Product: SDL Reporter: Jonas Kulla <ancurio_bugzilla>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   
Attachments: Quick n ugly fix

Description Jonas Kulla 2013-10-14 20:43:53 UTC
After commit d4a39491577f (https://hg.libsdl.org/SDL/rev/d4a39491577f), SDL crashes in 'SDL_ShowSimpleMessageBox()' for me (segmentation fault).

I have narrowed the problem down to (video/x11/SDL_x11messagebox.c:373):

    if ( messageboxdata->window ) {
        SDL_DisplayData *displaydata =
            (SDL_DisplayData *) SDL_GetDisplayForWindow(messageboxdata->window)->driverdata;
        windowdata = (SDL_WindowData *)messageboxdata->window->driverdata;
        data->screen = displaydata->screen;
    } else {
        data->screen = DefaultScreen( display );
    }

where SDL_GetDisplayForWindow (video/SDL_video.c:996):

    int displayIndex = SDL_GetWindowDisplayIndex(window);
    if (displayIndex >= 0) {
        return &_this->displays[displayIndex];
    } else {
        return NULL;
    }

'SDL_GetWindowDisplayIndex()' returns -1, making 'SDL_GetDisplayForWindow()' return NULL, while the first code snippet dereferences this NULL pointer (messageboxdata->window) and causes the segfault.

Anything else I can do to help find the problem?
Comment 1 Jonas Kulla 2013-10-14 20:46:20 UTC
Sorry, I meant to write the NULL pointer is dereferenced via "->driverdata".
Comment 2 Jonas Kulla 2013-10-14 21:03:14 UTC
Upon further investigation, there's something about this code calling the device vfunc (SDL_video.c:3141):

    if (_this && _this->ShowMessageBox) {
        retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
    }

The dereferenced function I see being called in my debugger is (SDL_x11messagebox.c:700):

int
X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)


Which on first sight looks like we're calling with the wrong signature. Could this be the problem?
Comment 3 Jonas Kulla 2013-10-14 21:23:41 UTC
Created attachment 1367 [details]
Quick n ugly fix
Comment 4 Sam Lantinga 2013-10-15 02:00:05 UTC
I actually fixed this earlier today, thanks for the report!
http://hg.libsdl.org/SDL/rev/a31914a35076
Comment 5 Jonas Kulla 2013-10-15 02:53:45 UTC
Oh, what a coincidence =) Thanks!