If the video system has been initialized, only use that message box system.
authorSam Lantinga <slouken@libsdl.org>
Sun, 14 Jul 2013 11:11:42 -0700
changeset 7452fae80e5464e2
parent 7451 2ce2d2c71156
child 7453 91c3bb321036
If the video system has been initialized, only use that message box system.
Don't pass a window from one video driver to the messagebox function of another video driver. This makes bad things happen. :)
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Sun Jul 14 19:56:22 2013 +0200
     1.2 +++ b/src/video/SDL_video.c	Sun Jul 14 11:11:42 2013 -0700
     1.3 @@ -3057,48 +3057,54 @@
     1.4  {
     1.5      int dummybutton;
     1.6      int retval = -1;
     1.7 -    SDL_bool relative_mode = SDL_GetRelativeMouseMode();
     1.8 -    int show_cursor_prev = SDL_ShowCursor( 1 );
     1.9 -
    1.10 -    SDL_SetRelativeMouseMode( SDL_FALSE );
    1.11 +    SDL_bool relative_mode;
    1.12 +    int show_cursor_prev;
    1.13 +
    1.14 +    if (!messageboxdata) {
    1.15 +        return SDL_InvalidParamError("messageboxdata");
    1.16 +    }
    1.17 +
    1.18 +    relative_mode = SDL_GetRelativeMouseMode();
    1.19 +    SDL_SetRelativeMouseMode(SDL_FALSE);
    1.20 +    show_cursor_prev = SDL_ShowCursor(1);
    1.21  
    1.22      if (!buttonid) {
    1.23          buttonid = &dummybutton;
    1.24      }
    1.25      if (_this && _this->ShowMessageBox) {
    1.26 -        if (_this->ShowMessageBox(_this, messageboxdata, buttonid) == 0) {
    1.27 -            retval = 0;
    1.28 +        retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
    1.29 +    } else {
    1.30 +        /* It's completely fine to call this function before video is initialized */
    1.31 +        if (messageboxdata->window == NULL) {
    1.32 +#if SDL_VIDEO_DRIVER_WINDOWS
    1.33 +            if ((retval == -1) && (WIN_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.34 +                retval = 0;
    1.35 +            }
    1.36 +#endif
    1.37 +#if SDL_VIDEO_DRIVER_COCOA
    1.38 +            if ((retval == -1) && (Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.39 +                retval = 0;
    1.40 +            }
    1.41 +#endif
    1.42 +#if SDL_VIDEO_DRIVER_UIKIT
    1.43 +            if ((retval == -1) && (UIKit_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.44 +                retval = 0;
    1.45 +            }
    1.46 +#endif
    1.47 +#if SDL_VIDEO_DRIVER_X11
    1.48 +            if ((retval == -1) && (X11_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.49 +                retval = 0;
    1.50 +            }
    1.51 +#endif
    1.52 +        }
    1.53 +        if (retval == -1) {
    1.54 +            SDL_SetError("No message system available");
    1.55          }
    1.56      }
    1.57  
    1.58 -    /* It's completely fine to call this function before video is initialized */
    1.59 -#if SDL_VIDEO_DRIVER_WINDOWS
    1.60 -    if ((retval == -1) && (WIN_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.61 -        retval = 0;
    1.62 -    }
    1.63 -#endif
    1.64 -#if SDL_VIDEO_DRIVER_COCOA
    1.65 -    if ((retval == -1) && (Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.66 -        retval = 0;
    1.67 -    }
    1.68 -#endif
    1.69 -#if SDL_VIDEO_DRIVER_UIKIT
    1.70 -    if ((retval == -1) && (UIKit_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.71 -        retval = 0;
    1.72 -    }
    1.73 -#endif
    1.74 -#if SDL_VIDEO_DRIVER_X11
    1.75 -    if ((retval == -1) && (X11_ShowMessageBox(messageboxdata, buttonid) == 0)) {
    1.76 -        retval = 0;
    1.77 -    }
    1.78 -#endif
    1.79 -
    1.80 -    SDL_ShowCursor( show_cursor_prev );
    1.81 -    SDL_SetRelativeMouseMode( relative_mode );
    1.82 -
    1.83 -    if(retval == -1) {
    1.84 -        SDL_SetError("No message system available");
    1.85 -    }
    1.86 +    SDL_ShowCursor(show_cursor_prev);
    1.87 +    SDL_SetRelativeMouseMode(relative_mode);
    1.88 +
    1.89      return retval;
    1.90  }
    1.91