Report an error if creating a render target fails
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
diff --git a/test/testrendertarget.c b/test/testrendertarget.c
index 03e8df1..4f49dce 100644
--- a/test/testrendertarget.c
+++ b/test/testrendertarget.c
@@ -87,7 +87,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
return texture;
}
-void
+SDL_bool
DrawComposite(DrawState *s)
{
SDL_Rect viewport, R;
@@ -167,9 +167,10 @@ DrawComposite(DrawState *s)
/* Update the screen! */
SDL_RenderPresent(s->renderer);
+ return SDL_TRUE;
}
-void
+SDL_bool
Draw(DrawState *s)
{
SDL_Rect viewport;
@@ -178,6 +179,10 @@ Draw(DrawState *s)
SDL_RenderGetViewport(s->renderer, &viewport);
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
+ if (!target) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
+ return SDL_FALSE;
+ }
SDL_SetRenderTarget(s->renderer, target);
/* Draw the background */
@@ -206,6 +211,7 @@ Draw(DrawState *s)
/* Update the screen! */
SDL_RenderPresent(s->renderer);
+ return SDL_TRUE;
}
int
@@ -280,9 +286,9 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
if (test_composite) {
- DrawComposite(&drawstates[i]);
+ if (!DrawComposite(&drawstates[i])) done = 1;
} else {
- Draw(&drawstates[i]);
+ if (!Draw(&drawstates[i])) done = 1;
}
}
}