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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 05d72a2..4e9429e 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -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;
diff --git a/test/testdraw2.c b/test/testdraw2.c
index 926294b..62e2dbf 100644
--- a/test/testdraw2.c
+++ b/test/testdraw2.c
@@ -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);
diff --git a/test/testgl2.c b/test/testgl2.c
index 642fe47..19685ea 100644
--- a/test/testgl2.c
+++ b/test/testgl2.c
@@ -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);
diff --git a/test/testgles.c b/test/testgles.c
index 7a790bd..daaa28c 100644
--- a/test/testgles.c
+++ b/test/testgles.c
@@ -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());
diff --git a/test/testime.c b/test/testime.c
index 93b33e0..3d9789a 100644
--- a/test/testime.c
+++ b/test/testime.c
@@ -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);
diff --git a/test/testintersections.c b/test/testintersections.c
index 237bd35..b4deeec 100644
--- a/test/testintersections.c
+++ b/test/testintersections.c
@@ -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);
diff --git a/test/testrelative.c b/test/testrelative.c
index 478d3bf..9e8e1e2 100644
--- a/test/testrelative.c
+++ b/test/testrelative.c
@@ -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);
diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c
index 5033c1c..0c8ad7d 100644
--- a/test/testrendercopyex.c
+++ b/test/testrendercopyex.c
@@ -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]);
}
}
diff --git a/test/testrendertarget.c b/test/testrendertarget.c
index 4f49dce..ac4aa50 100644
--- a/test/testrendertarget.c
+++ b/test/testrendertarget.c
@@ -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 {
diff --git a/test/testscale.c b/test/testscale.c
index f81ccdc..8449f23 100644
--- a/test/testscale.c
+++ b/test/testscale.c
@@ -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]);
}
}
diff --git a/test/testsprite2.c b/test/testsprite2.c
index b40efd3..e0e1cf4 100644
--- a/test/testsprite2.c
+++ b/test/testsprite2.c
@@ -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]);
}
}