Added magic to detect already freed or otherwise invalid windows and textures.
authorSam Lantinga <slouken@libsdl.org>
Sun, 24 Jan 2010 20:21:51 +0000
changeset 3695f6a8be3fefa0
parent 3694 b0a707f589a6
child 3696 47d923feedb0
Added magic to detect already freed or otherwise invalid windows and textures.
src/video/SDL_sysvideo.h
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_sysvideo.h	Sun Jan 24 19:47:17 2010 +0000
     1.2 +++ b/src/video/SDL_sysvideo.h	Sun Jan 24 20:21:51 2010 +0000
     1.3 @@ -37,6 +37,7 @@
     1.4  /* Define the SDL texture structure */
     1.5  struct SDL_Texture
     1.6  {
     1.7 +    const void *magic;
     1.8      Uint32 format;              /**< The pixel format of the texture */
     1.9      int access;                 /**< SDL_TextureAccess */
    1.10      int w;                      /**< The width of the texture */
    1.11 @@ -138,6 +139,7 @@
    1.12  /* Define the SDL window structure, corresponding to toplevel windows */
    1.13  struct SDL_Window
    1.14  {
    1.15 +    const void *magic;
    1.16      Uint32 id;
    1.17      char *title;
    1.18      int x, y;
    1.19 @@ -308,6 +310,8 @@
    1.20      int num_displays;
    1.21      SDL_VideoDisplay *displays;
    1.22      int current_display;
    1.23 +    Uint8 window_magic;
    1.24 +    Uint8 texture_magic;
    1.25      Uint32 next_object_id;
    1.26  
    1.27      /* * * */
     2.1 --- a/src/video/SDL_video.c	Sun Jan 24 19:47:17 2010 +0000
     2.2 +++ b/src/video/SDL_video.c	Sun Jan 24 20:21:51 2010 +0000
     2.3 @@ -105,6 +105,26 @@
     2.4  
     2.5  static SDL_VideoDevice *_this = NULL;
     2.6  
     2.7 +#define CHECK_WINDOW_MAGIC(window, retval) \
     2.8 +    if (!_this) { \
     2.9 +        SDL_UninitializedVideo(); \
    2.10 +        return retval; \
    2.11 +    } \
    2.12 +	if (!window || window->magic != &_this->window_magic) { \
    2.13 +        SDL_SetError("Invalid window"); \
    2.14 +        return retval; \
    2.15 +    }
    2.16 +
    2.17 +#define CHECK_TEXTURE_MAGIC(texture, retval) \
    2.18 +    if (!_this) { \
    2.19 +        SDL_UninitializedVideo(); \
    2.20 +        return retval; \
    2.21 +    } \
    2.22 +	if (!texture || texture->magic != &_this->texture_magic) { \
    2.23 +        SDL_SetError("Invalid texture"); \
    2.24 +        return retval; \
    2.25 +    }
    2.26 +
    2.27  /* Various local functions */
    2.28  static void SDL_UpdateWindowGrab(SDL_Window * window);
    2.29  
    2.30 @@ -710,9 +730,7 @@
    2.31  int
    2.32  SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
    2.33  {
    2.34 -    if (!window) {
    2.35 -        return -1;
    2.36 -    }
    2.37 +    CHECK_WINDOW_MAGIC(window, -1);
    2.38  
    2.39      if (mode) {
    2.40          window->fullscreen_mode = *mode;
    2.41 @@ -727,9 +745,7 @@
    2.42  {
    2.43      SDL_DisplayMode fullscreen_mode;
    2.44  
    2.45 -    if (!window) {
    2.46 -        return -1;
    2.47 -    }
    2.48 +    CHECK_WINDOW_MAGIC(window, -1);
    2.49  
    2.50      fullscreen_mode = window->fullscreen_mode;
    2.51      if (!fullscreen_mode.w) {
    2.52 @@ -897,6 +913,7 @@
    2.53      }
    2.54      display = SDL_CurrentDisplay;
    2.55      window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
    2.56 +    window->magic = &_this->window_magic;
    2.57      window->id = _this->next_object_id++;
    2.58      window->x = x;
    2.59      window->y = y;
    2.60 @@ -944,6 +961,7 @@
    2.61      }
    2.62      display = SDL_CurrentDisplay;
    2.63      window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
    2.64 +    window->magic = &_this->window_magic;
    2.65      window->id = _this->next_object_id++;
    2.66      window->flags = SDL_WINDOW_FOREIGN;
    2.67      window->display = display;
    2.68 @@ -1047,9 +1065,8 @@
    2.69  Uint32
    2.70  SDL_GetWindowID(SDL_Window * window)
    2.71  {
    2.72 -    if (!window) {
    2.73 -        return 0;
    2.74 -    }
    2.75 +    CHECK_WINDOW_MAGIC(window, 0);
    2.76 +
    2.77      return window->id;
    2.78  }
    2.79  
    2.80 @@ -1077,16 +1094,17 @@
    2.81  Uint32
    2.82  SDL_GetWindowFlags(SDL_Window * window)
    2.83  {
    2.84 -    if (!window) {
    2.85 -        return 0;
    2.86 -    }
    2.87 +    CHECK_WINDOW_MAGIC(window, 0);
    2.88 +
    2.89      return window->flags;
    2.90  }
    2.91  
    2.92  void
    2.93  SDL_SetWindowTitle(SDL_Window * window, const char *title)
    2.94  {
    2.95 -    if (!window || title == window->title) {
    2.96 +    CHECK_WINDOW_MAGIC(window, );
    2.97 +
    2.98 +    if (title == window->title) {
    2.99          return;
   2.100      }
   2.101      if (window->title) {
   2.102 @@ -1106,18 +1124,16 @@
   2.103  const char *
   2.104  SDL_GetWindowTitle(SDL_Window * window)
   2.105  {
   2.106 -    if (!window) {
   2.107 -        return NULL;
   2.108 -    }
   2.109 +    CHECK_WINDOW_MAGIC(window, NULL);
   2.110 +
   2.111      return window->title;
   2.112  }
   2.113  
   2.114  void
   2.115  SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
   2.116  {
   2.117 -    if (!window) {
   2.118 -        return;
   2.119 -    }
   2.120 +    CHECK_WINDOW_MAGIC(window, );
   2.121 +
   2.122      if (_this->SetWindowIcon) {
   2.123          _this->SetWindowIcon(_this, window, icon);
   2.124      }
   2.125 @@ -1126,27 +1142,24 @@
   2.126  void
   2.127  SDL_SetWindowData(SDL_Window * window, void *userdata)
   2.128  {
   2.129 -    if (!window) {
   2.130 -        return;
   2.131 -    }
   2.132 +    CHECK_WINDOW_MAGIC(window, );
   2.133 +
   2.134      window->userdata = userdata;
   2.135  }
   2.136  
   2.137  void *
   2.138  SDL_GetWindowData(SDL_Window * window)
   2.139  {
   2.140 -    if (!window) {
   2.141 -        return NULL;
   2.142 -    }
   2.143 +    CHECK_WINDOW_MAGIC(window, NULL);
   2.144 +
   2.145      return window->userdata;
   2.146  }
   2.147  
   2.148  void
   2.149  SDL_SetWindowPosition(SDL_Window * window, int x, int y)
   2.150  {
   2.151 -    if (!window) {
   2.152 -        return;
   2.153 -    }
   2.154 +    CHECK_WINDOW_MAGIC(window, );
   2.155 +
   2.156      if (x != SDL_WINDOWPOS_UNDEFINED) {
   2.157          window->x = x;
   2.158      }
   2.159 @@ -1162,9 +1175,8 @@
   2.160  void
   2.161  SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
   2.162  {
   2.163 -    if (!window) {
   2.164 -        return;
   2.165 -    }
   2.166 +    CHECK_WINDOW_MAGIC(window, );
   2.167 +
   2.168      if (x) {
   2.169          *x = window->x;
   2.170      }
   2.171 @@ -1176,9 +1188,8 @@
   2.172  void
   2.173  SDL_SetWindowSize(SDL_Window * window, int w, int h)
   2.174  {
   2.175 -    if (!window) {
   2.176 -        return;
   2.177 -    }
   2.178 +    CHECK_WINDOW_MAGIC(window, );
   2.179 +
   2.180      window->w = w;
   2.181      window->h = h;
   2.182  
   2.183 @@ -1211,7 +1222,9 @@
   2.184  void
   2.185  SDL_ShowWindow(SDL_Window * window)
   2.186  {
   2.187 -    if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
   2.188 +    CHECK_WINDOW_MAGIC(window, );
   2.189 +
   2.190 +    if (window->flags & SDL_WINDOW_SHOWN) {
   2.191          return;
   2.192      }
   2.193  
   2.194 @@ -1224,7 +1237,9 @@
   2.195  void
   2.196  SDL_HideWindow(SDL_Window * window)
   2.197  {
   2.198 -    if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   2.199 +    CHECK_WINDOW_MAGIC(window, );
   2.200 +
   2.201 +    if (!(window->flags & SDL_WINDOW_SHOWN)) {
   2.202          return;
   2.203      }
   2.204  
   2.205 @@ -1237,7 +1252,9 @@
   2.206  void
   2.207  SDL_RaiseWindow(SDL_Window * window)
   2.208  {
   2.209 -    if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   2.210 +    CHECK_WINDOW_MAGIC(window, );
   2.211 +
   2.212 +    if (!(window->flags & SDL_WINDOW_SHOWN)) {
   2.213          return;
   2.214      }
   2.215      if (_this->RaiseWindow) {
   2.216 @@ -1251,7 +1268,9 @@
   2.217  void
   2.218  SDL_MaximizeWindow(SDL_Window * window)
   2.219  {
   2.220 -    if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
   2.221 +    CHECK_WINDOW_MAGIC(window, );
   2.222 +
   2.223 +    if (window->flags & SDL_WINDOW_MAXIMIZED) {
   2.224          return;
   2.225      }
   2.226  
   2.227 @@ -1264,7 +1283,9 @@
   2.228  void
   2.229  SDL_MinimizeWindow(SDL_Window * window)
   2.230  {
   2.231 -    if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
   2.232 +    CHECK_WINDOW_MAGIC(window, );
   2.233 +
   2.234 +    if (window->flags & SDL_WINDOW_MINIMIZED) {
   2.235          return;
   2.236      }
   2.237  
   2.238 @@ -1277,8 +1298,9 @@
   2.239  void
   2.240  SDL_RestoreWindow(SDL_Window * window)
   2.241  {
   2.242 -    if (!window
   2.243 -        || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
   2.244 +    CHECK_WINDOW_MAGIC(window, );
   2.245 +
   2.246 +    if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
   2.247          return;
   2.248      }
   2.249  
   2.250 @@ -1291,9 +1313,8 @@
   2.251  int
   2.252  SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen)
   2.253  {
   2.254 -    if (!window) {
   2.255 -        return -1;
   2.256 -    }
   2.257 +    CHECK_WINDOW_MAGIC(window, -1);
   2.258 +
   2.259      if (fullscreen) {
   2.260          fullscreen = SDL_WINDOW_FULLSCREEN;
   2.261      }
   2.262 @@ -1315,7 +1336,9 @@
   2.263  void
   2.264  SDL_SetWindowGrab(SDL_Window * window, int mode)
   2.265  {
   2.266 -    if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
   2.267 +    CHECK_WINDOW_MAGIC(window, );
   2.268 +
   2.269 +    if ((!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
   2.270          return;
   2.271      }
   2.272      if (mode) {
   2.273 @@ -1337,9 +1360,8 @@
   2.274  int
   2.275  SDL_GetWindowGrab(SDL_Window * window)
   2.276  {
   2.277 -    if (!window) {
   2.278 -        return 0;
   2.279 -    }
   2.280 +    CHECK_WINDOW_MAGIC(window, 0);
   2.281 +
   2.282      return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
   2.283  }
   2.284  
   2.285 @@ -1436,10 +1458,8 @@
   2.286  {
   2.287      SDL_VideoDisplay *display;
   2.288  
   2.289 -    if (!_this || !window || !window->id) {
   2.290 -        SDL_SetError("Invalid window");
   2.291 -        return;
   2.292 -    }
   2.293 +    CHECK_WINDOW_MAGIC(window, );
   2.294 +    window->magic = NULL;
   2.295  
   2.296      if (window->title) {
   2.297          SDL_free(window->title);
   2.298 @@ -1469,9 +1489,6 @@
   2.299          display->windows = window->next;
   2.300      }
   2.301  
   2.302 -    /* Clear the ID so we know it was destroyed */
   2.303 -    window->id = 0;
   2.304 -
   2.305      SDL_free(window);
   2.306  }
   2.307  
   2.308 @@ -1519,10 +1536,7 @@
   2.309  int
   2.310  SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
   2.311  {
   2.312 -    if (!window) {
   2.313 -        SDL_SetError("Invalid window");
   2.314 -        return -1;
   2.315 -    }
   2.316 +    CHECK_WINDOW_MAGIC(window, -1);
   2.317  
   2.318      /* Free any existing renderer */
   2.319      SDL_DestroyRenderer(window);
   2.320 @@ -1596,10 +1610,8 @@
   2.321  {
   2.322      SDL_Renderer *renderer;
   2.323  
   2.324 -    if (!window) {
   2.325 -        SDL_SetError("Invalid window");
   2.326 -        return -1;
   2.327 -    }
   2.328 +    CHECK_WINDOW_MAGIC(window, -1);
   2.329 +
   2.330      renderer = window->renderer;
   2.331      if (!renderer) {
   2.332          SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
   2.333 @@ -1644,6 +1656,7 @@
   2.334          SDL_OutOfMemory();
   2.335          return 0;
   2.336      }
   2.337 +    texture->magic = &_this->texture_magic;
   2.338      texture->format = format;
   2.339      texture->access = access;
   2.340      texture->w = w;
   2.341 @@ -1972,9 +1985,8 @@
   2.342  SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
   2.343                   int *w, int *h)
   2.344  {
   2.345 -    if (!texture) {
   2.346 -        return -1;
   2.347 -    }
   2.348 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.349 +
   2.350      if (format) {
   2.351          *format = texture->format;
   2.352      }
   2.353 @@ -1995,9 +2007,8 @@
   2.354  {
   2.355      SDL_Renderer *renderer;
   2.356  
   2.357 -    if (!texture) {
   2.358 -        return -1;
   2.359 -    }
   2.360 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.361 +
   2.362      renderer = texture->renderer;
   2.363      if (!renderer->QueryTexturePixels) {
   2.364          SDL_Unsupported();
   2.365 @@ -2012,9 +2023,8 @@
   2.366  {
   2.367      SDL_Renderer *renderer;
   2.368  
   2.369 -    if (!texture) {
   2.370 -        return -1;
   2.371 -    }
   2.372 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.373 +
   2.374      renderer = texture->renderer;
   2.375      if (!renderer->SetTexturePalette) {
   2.376          SDL_Unsupported();
   2.377 @@ -2030,9 +2040,8 @@
   2.378  {
   2.379      SDL_Renderer *renderer;
   2.380  
   2.381 -    if (!texture) {
   2.382 -        return -1;
   2.383 -    }
   2.384 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.385 +
   2.386      renderer = texture->renderer;
   2.387      if (!renderer->GetTexturePalette) {
   2.388          SDL_Unsupported();
   2.389 @@ -2047,9 +2056,8 @@
   2.390  {
   2.391      SDL_Renderer *renderer;
   2.392  
   2.393 -    if (!texture) {
   2.394 -        return -1;
   2.395 -    }
   2.396 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.397 +
   2.398      renderer = texture->renderer;
   2.399      if (!renderer->SetTextureColorMod) {
   2.400          SDL_Unsupported();
   2.401 @@ -2072,9 +2080,8 @@
   2.402  {
   2.403      SDL_Renderer *renderer;
   2.404  
   2.405 -    if (!texture) {
   2.406 -        return -1;
   2.407 -    }
   2.408 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.409 +
   2.410      renderer = texture->renderer;
   2.411      if (r) {
   2.412          *r = texture->r;
   2.413 @@ -2093,9 +2100,8 @@
   2.414  {
   2.415      SDL_Renderer *renderer;
   2.416  
   2.417 -    if (!texture) {
   2.418 -        return -1;
   2.419 -    }
   2.420 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.421 +
   2.422      renderer = texture->renderer;
   2.423      if (!renderer->SetTextureAlphaMod) {
   2.424          SDL_Unsupported();
   2.425 @@ -2113,9 +2119,8 @@
   2.426  int
   2.427  SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
   2.428  {
   2.429 -    if (!texture) {
   2.430 -        return -1;
   2.431 -    }
   2.432 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.433 +
   2.434      if (alpha) {
   2.435          *alpha = texture->a;
   2.436      }
   2.437 @@ -2127,9 +2132,8 @@
   2.438  {
   2.439      SDL_Renderer *renderer;
   2.440  
   2.441 -    if (!texture) {
   2.442 -        return -1;
   2.443 -    }
   2.444 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.445 +
   2.446      renderer = texture->renderer;
   2.447      if (!renderer->SetTextureBlendMode) {
   2.448          SDL_Unsupported();
   2.449 @@ -2142,9 +2146,8 @@
   2.450  int
   2.451  SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode)
   2.452  {
   2.453 -    if (!texture) {
   2.454 -        return -1;
   2.455 -    }
   2.456 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.457 +
   2.458      if (blendMode) {
   2.459          *blendMode = texture->blendMode;
   2.460      }
   2.461 @@ -2156,9 +2159,8 @@
   2.462  {
   2.463      SDL_Renderer *renderer;
   2.464  
   2.465 -    if (!texture) {
   2.466 -        return -1;
   2.467 -    }
   2.468 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.469 +
   2.470      renderer = texture->renderer;
   2.471      if (!renderer->SetTextureScaleMode) {
   2.472          SDL_Unsupported();
   2.473 @@ -2171,9 +2173,8 @@
   2.474  int
   2.475  SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode)
   2.476  {
   2.477 -    if (!texture) {
   2.478 -        return -1;
   2.479 -    }
   2.480 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.481 +
   2.482      if (scaleMode) {
   2.483          *scaleMode = texture->scaleMode;
   2.484      }
   2.485 @@ -2187,9 +2188,8 @@
   2.486      SDL_Renderer *renderer;
   2.487      SDL_Rect full_rect;
   2.488  
   2.489 -    if (!texture) {
   2.490 -        return -1;
   2.491 -    }
   2.492 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.493 +
   2.494      renderer = texture->renderer;
   2.495      if (!renderer->UpdateTexture) {
   2.496          SDL_Unsupported();
   2.497 @@ -2212,9 +2212,8 @@
   2.498      SDL_Renderer *renderer;
   2.499      SDL_Rect full_rect;
   2.500  
   2.501 -    if (!texture) {
   2.502 -        return -1;
   2.503 -    }
   2.504 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.505 +
   2.506      if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   2.507          SDL_SetError("SDL_LockTexture(): texture must be streaming");
   2.508          return -1;
   2.509 @@ -2240,9 +2239,8 @@
   2.510  {
   2.511      SDL_Renderer *renderer;
   2.512  
   2.513 -    if (!texture) {
   2.514 -        return;
   2.515 -    }
   2.516 +    CHECK_TEXTURE_MAGIC(texture, );
   2.517 +
   2.518      if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   2.519          return;
   2.520      }
   2.521 @@ -2259,9 +2257,8 @@
   2.522  {
   2.523      SDL_Renderer *renderer;
   2.524  
   2.525 -    if (!texture) {
   2.526 -        return;
   2.527 -    }
   2.528 +    CHECK_TEXTURE_MAGIC(texture, );
   2.529 +
   2.530      if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
   2.531          return;
   2.532      }
   2.533 @@ -2544,14 +2541,12 @@
   2.534      SDL_Rect real_srcrect;
   2.535      SDL_Rect real_dstrect;
   2.536  
   2.537 +    CHECK_TEXTURE_MAGIC(texture, -1);
   2.538 +
   2.539      renderer = SDL_GetCurrentRenderer(SDL_TRUE);
   2.540      if (!renderer) {
   2.541          return -1;
   2.542      }
   2.543 -    if (!texture) {
   2.544 -        SDL_SetError("Texture not found");
   2.545 -        return -1;
   2.546 -    }
   2.547      if (texture->renderer != renderer) {
   2.548          SDL_SetError("Texture was not created with this renderer");
   2.549          return -1;
   2.550 @@ -2704,10 +2699,8 @@
   2.551  {
   2.552      SDL_Renderer *renderer;
   2.553  
   2.554 -    if (!texture || !texture->renderer) {
   2.555 -        SDL_SetError("Invalid texture");
   2.556 -        return;
   2.557 -    }
   2.558 +    CHECK_TEXTURE_MAGIC(texture, );
   2.559 +    texture->magic = NULL;
   2.560  
   2.561      renderer = texture->renderer;
   2.562      if (texture->next) {
   2.563 @@ -2718,7 +2711,6 @@
   2.564      } else {
   2.565          renderer->textures = texture->next;
   2.566      }
   2.567 -    texture->renderer = NULL;
   2.568  
   2.569      renderer->DestroyTexture(renderer, texture);
   2.570      SDL_free(texture);
   2.571 @@ -2729,9 +2721,8 @@
   2.572  {
   2.573      SDL_Renderer *renderer;
   2.574  
   2.575 -    if (!window) {
   2.576 -        return;
   2.577 -    }
   2.578 +    CHECK_WINDOW_MAGIC(window, );
   2.579 +
   2.580      renderer = window->renderer;
   2.581      if (!renderer) {
   2.582          return;
   2.583 @@ -3215,9 +3206,8 @@
   2.584  SDL_GLContext
   2.585  SDL_GL_CreateContext(SDL_Window * window)
   2.586  {
   2.587 -    if (!window) {
   2.588 -        return NULL;
   2.589 -    }
   2.590 +    CHECK_WINDOW_MAGIC(window, NULL);
   2.591 +
   2.592      if (!(window->flags & SDL_WINDOW_OPENGL)) {
   2.593          SDL_SetError("The specified window isn't an OpenGL window");
   2.594          return NULL;
   2.595 @@ -3228,7 +3218,9 @@
   2.596  int
   2.597  SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
   2.598  {
   2.599 -    if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
   2.600 +    CHECK_WINDOW_MAGIC(window, -1);
   2.601 +
   2.602 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
   2.603          SDL_SetError("The specified window isn't an OpenGL window");
   2.604          return -1;
   2.605      }
   2.606 @@ -3271,9 +3263,8 @@
   2.607  void
   2.608  SDL_GL_SwapWindow(SDL_Window * window)
   2.609  {
   2.610 -    if (!window) {
   2.611 -        return;
   2.612 -    }
   2.613 +    CHECK_WINDOW_MAGIC(window, );
   2.614 +
   2.615      if (!(window->flags & SDL_WINDOW_OPENGL)) {
   2.616          SDL_SetError("The specified window isn't an OpenGL window");
   2.617          return;
   2.618 @@ -3393,7 +3384,9 @@
   2.619  SDL_bool
   2.620  SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
   2.621  {
   2.622 -    if (!window || !_this->GetWindowWMInfo) {
   2.623 +    CHECK_WINDOW_MAGIC(window, SDL_FALSE);
   2.624 +
   2.625 +    if (!_this->GetWindowWMInfo) {
   2.626          return SDL_FALSE;
   2.627      }
   2.628      return (_this->GetWindowWMInfo(_this, window, info));