From 6a305e1532e46c33c153b882f7b9f237434d4870 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 13 Sep 2024 19:06:43 +0200
Subject: [PATCH] SDL_test: fix SDLTest_CommonQuit with NULL state
---
src/test/SDL_test_common.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 7b142e2b7afa0..6ce631cc54765 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -2543,29 +2543,31 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
void SDLTest_CommonQuit(SDLTest_CommonState *state)
{
- int i;
+ if (state) {
+ int i;
- if (state->targets) {
- for (i = 0; i < state->num_windows; ++i) {
- if (state->targets[i]) {
- SDL_DestroyTexture(state->targets[i]);
+ if (state->targets) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (state->targets[i]) {
+ SDL_DestroyTexture(state->targets[i]);
+ }
}
+ SDL_free(state->targets);
}
- SDL_free(state->targets);
- }
- if (state->renderers) {
- for (i = 0; i < state->num_windows; ++i) {
- if (state->renderers[i]) {
- SDL_DestroyRenderer(state->renderers[i]);
+ if (state->renderers) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (state->renderers[i]) {
+ SDL_DestroyRenderer(state->renderers[i]);
+ }
}
+ SDL_free(state->renderers);
}
- SDL_free(state->renderers);
- }
- if (state->windows) {
- for (i = 0; i < state->num_windows; i++) {
- SDL_DestroyWindow(state->windows[i]);
+ if (state->windows) {
+ for (i = 0; i < state->num_windows; i++) {
+ SDL_DestroyWindow(state->windows[i]);
+ }
+ SDL_free(state->windows);
}
- SDL_free(state->windows);
}
SDL_Quit();
SDLTest_CommonDestroyState(state);