Commit 9cbd05df1ec14d0453c4fa3b39435839f41ac36d

Sam Lantinga 2013-10-03T21:41:09

Report an error if creating a render target fails

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;
             }
         }
     }