Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug 2132 - Tests may use invalid SDL_window pointers when windo…
…ws 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.
  • Loading branch information
slouken committed Oct 6, 2013
1 parent 0db36f5 commit 5296642
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/test/SDL_test_common.c
Expand Up @@ -1200,6 +1200,12 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
if (window) {
SDL_DestroyWindow(window);
for (i = 0; i < state->num_windows; ++i) {
if (window == state->windows[i]) {
state->windows[i] = NULL;
break;
}
}
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions test/testdraw2.c
Expand Up @@ -253,6 +253,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

Expand Down
2 changes: 2 additions & 0 deletions test/testgl2.c
Expand Up @@ -340,6 +340,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
int w, h;
if (state->windows[i] == NULL)
continue;
SDL_GL_MakeCurrent(state->windows[i], context);
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
glViewport(0, 0, w, h);
Expand Down
2 changes: 2 additions & 0 deletions test/testgles.c
Expand Up @@ -312,6 +312,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
Expand Down
2 changes: 2 additions & 0 deletions test/testime.c
Expand Up @@ -196,6 +196,8 @@ void Redraw() {
int i;
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);

Expand Down
2 changes: 2 additions & 0 deletions test/testintersections.c
Expand Up @@ -310,6 +310,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

Expand Down
2 changes: 2 additions & 0 deletions test/testrelative.c
Expand Up @@ -84,6 +84,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

Expand Down
2 changes: 2 additions & 0 deletions test/testrendercopyex.c
Expand Up @@ -188,6 +188,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
Draw(&drawstates[i]);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/testrendertarget.c
Expand Up @@ -285,6 +285,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
if (test_composite) {
if (!DrawComposite(&drawstates[i])) done = 1;
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/testscale.c
Expand Up @@ -178,6 +178,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
Draw(&drawstates[i]);
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/testsprite2.c
Expand Up @@ -360,6 +360,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
MoveSprites(state->renderers[i], sprites[i]);
}
}
Expand Down

0 comments on commit 5296642

Please sign in to comment.