Fixed bug 2132 - Tests may use invalid SDL_window pointers when windows are closed
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Oct 2013 19:09:03 -0700
changeset 7787e6f3e8fc96ea
parent 7786 cfc1285375e1
child 7788 25355ecf10aa
Fixed bug 2132 - Tests may use invalid SDL_window pointers when windows are closed

norfanin

Some of the tests keep using the pointers of a destroyed SDL_Window when the common event handling handled the close event. The event handler itself does not NULL the pointer after the destruction.

The attached patch adds a loop in the handler that will assign NULL to the destroyed window. It also adds checks to some of the tests so they skip those windows by checking for NULL.
src/test/SDL_test_common.c
test/testdraw2.c
test/testgl2.c
test/testgles.c
test/testime.c
test/testintersections.c
test/testrelative.c
test/testrendercopyex.c
test/testrendertarget.c
test/testscale.c
test/testsprite2.c
     1.1 --- a/src/test/SDL_test_common.c	Sat Oct 05 17:08:19 2013 +0200
     1.2 +++ b/src/test/SDL_test_common.c	Sat Oct 05 19:09:03 2013 -0700
     1.3 @@ -1200,6 +1200,12 @@
     1.4                  SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
     1.5                  if (window) {
     1.6                      SDL_DestroyWindow(window);
     1.7 +                    for (i = 0; i < state->num_windows; ++i) {
     1.8 +                        if (window == state->windows[i]) {
     1.9 +                            state->windows[i] = NULL;
    1.10 +                            break;
    1.11 +                        }
    1.12 +                    }
    1.13                  }
    1.14              }
    1.15              break;
     2.1 --- a/test/testdraw2.c	Sat Oct 05 17:08:19 2013 +0200
     2.2 +++ b/test/testdraw2.c	Sat Oct 05 19:09:03 2013 -0700
     2.3 @@ -253,6 +253,8 @@
     2.4          }
     2.5          for (i = 0; i < state->num_windows; ++i) {
     2.6              SDL_Renderer *renderer = state->renderers[i];
     2.7 +            if (state->windows[i] == NULL)
     2.8 +                continue;
     2.9              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    2.10              SDL_RenderClear(renderer);
    2.11  
     3.1 --- a/test/testgl2.c	Sat Oct 05 17:08:19 2013 +0200
     3.2 +++ b/test/testgl2.c	Sat Oct 05 19:09:03 2013 -0700
     3.3 @@ -340,6 +340,8 @@
     3.4          }
     3.5          for (i = 0; i < state->num_windows; ++i) {
     3.6              int w, h;
     3.7 +            if (state->windows[i] == NULL)
     3.8 +                continue;
     3.9              SDL_GL_MakeCurrent(state->windows[i], context);
    3.10              SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
    3.11              glViewport(0, 0, w, h);
     4.1 --- a/test/testgles.c	Sat Oct 05 17:08:19 2013 +0200
     4.2 +++ b/test/testgles.c	Sat Oct 05 19:09:03 2013 -0700
     4.3 @@ -312,6 +312,8 @@
     4.4              SDLTest_CommonEvent(state, &event, &done);
     4.5          }
     4.6          for (i = 0; i < state->num_windows; ++i) {
     4.7 +            if (state->windows[i] == NULL)
     4.8 +                continue;
     4.9              status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
    4.10              if (status) {
    4.11                  SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
     5.1 --- a/test/testime.c	Sat Oct 05 17:08:19 2013 +0200
     5.2 +++ b/test/testime.c	Sat Oct 05 19:09:03 2013 -0700
     5.3 @@ -196,6 +196,8 @@
     5.4      int i;
     5.5      for (i = 0; i < state->num_windows; ++i) {
     5.6          SDL_Renderer *renderer = state->renderers[i];
     5.7 +        if (state->windows[i] == NULL)
     5.8 +            continue;
     5.9          SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
    5.10          SDL_RenderClear(renderer);
    5.11  
     6.1 --- a/test/testintersections.c	Sat Oct 05 17:08:19 2013 +0200
     6.2 +++ b/test/testintersections.c	Sat Oct 05 19:09:03 2013 -0700
     6.3 @@ -310,6 +310,8 @@
     6.4          }
     6.5          for (i = 0; i < state->num_windows; ++i) {
     6.6              SDL_Renderer *renderer = state->renderers[i];
     6.7 +            if (state->windows[i] == NULL)
     6.8 +                continue;
     6.9              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    6.10              SDL_RenderClear(renderer);
    6.11  
     7.1 --- a/test/testrelative.c	Sat Oct 05 17:08:19 2013 +0200
     7.2 +++ b/test/testrelative.c	Sat Oct 05 19:09:03 2013 -0700
     7.3 @@ -84,6 +84,8 @@
     7.4          }
     7.5          for (i = 0; i < state->num_windows; ++i) {
     7.6              SDL_Renderer *renderer = state->renderers[i];
     7.7 +            if (state->windows[i] == NULL)
     7.8 +                continue;
     7.9              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    7.10              SDL_RenderClear(renderer);
    7.11  
     8.1 --- a/test/testrendercopyex.c	Sat Oct 05 17:08:19 2013 +0200
     8.2 +++ b/test/testrendercopyex.c	Sat Oct 05 19:09:03 2013 -0700
     8.3 @@ -188,6 +188,8 @@
     8.4              SDLTest_CommonEvent(state, &event, &done);
     8.5          }
     8.6          for (i = 0; i < state->num_windows; ++i) {
     8.7 +            if (state->windows[i] == NULL)
     8.8 +                continue;
     8.9              Draw(&drawstates[i]);
    8.10          }
    8.11      }
     9.1 --- a/test/testrendertarget.c	Sat Oct 05 17:08:19 2013 +0200
     9.2 +++ b/test/testrendertarget.c	Sat Oct 05 19:09:03 2013 -0700
     9.3 @@ -285,6 +285,8 @@
     9.4              SDLTest_CommonEvent(state, &event, &done);
     9.5          }
     9.6          for (i = 0; i < state->num_windows; ++i) {
     9.7 +            if (state->windows[i] == NULL)
     9.8 +                continue;
     9.9              if (test_composite) {
    9.10                  if (!DrawComposite(&drawstates[i])) done = 1;
    9.11              } else {
    10.1 --- a/test/testscale.c	Sat Oct 05 17:08:19 2013 +0200
    10.2 +++ b/test/testscale.c	Sat Oct 05 19:09:03 2013 -0700
    10.3 @@ -178,6 +178,8 @@
    10.4              SDLTest_CommonEvent(state, &event, &done);
    10.5          }
    10.6          for (i = 0; i < state->num_windows; ++i) {
    10.7 +            if (state->windows[i] == NULL)
    10.8 +                continue;
    10.9              Draw(&drawstates[i]);
   10.10          }
   10.11      }
    11.1 --- a/test/testsprite2.c	Sat Oct 05 17:08:19 2013 +0200
    11.2 +++ b/test/testsprite2.c	Sat Oct 05 19:09:03 2013 -0700
    11.3 @@ -360,6 +360,8 @@
    11.4              SDLTest_CommonEvent(state, &event, &done);
    11.5          }
    11.6          for (i = 0; i < state->num_windows; ++i) {
    11.7 +            if (state->windows[i] == NULL)
    11.8 +                continue;
    11.9              MoveSprites(state->renderers[i], sprites[i]);
   11.10          }
   11.11      }