Add an "error" label in SDL_CreateRenderer (no op)
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
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 9bf0d20..abdca68 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -839,12 +839,12 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
if (!window) {
SDL_SetError("Invalid window");
- return NULL;
+ goto error;
}
if (SDL_GetRenderer(window)) {
SDL_SetError("Renderer already associated with window");
- return NULL;
+ goto error;
}
if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
@@ -888,67 +888,74 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
}
if (index == n) {
SDL_SetError("Couldn't find matching render driver");
- return NULL;
+ goto error;
}
} else {
if (index >= SDL_GetNumRenderDrivers()) {
SDL_SetError("index must be -1 or in the range of 0 - %d",
SDL_GetNumRenderDrivers() - 1);
- return NULL;
+ goto error;
}
/* Create a new renderer instance */
renderer = render_drivers[index]->CreateRenderer(window, flags);
batching = SDL_FALSE;
}
- if (renderer) {
- VerifyDrawQueueFunctions(renderer);
+ if (!renderer) {
+ goto error;
+ }
- /* let app/user override batching decisions. */
- if (renderer->always_batch) {
- batching = SDL_TRUE;
- } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
- batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
- }
+ VerifyDrawQueueFunctions(renderer);
- renderer->batching = batching;
- renderer->magic = &renderer_magic;
- renderer->window = window;
- renderer->target_mutex = SDL_CreateMutex();
- renderer->scale.x = 1.0f;
- renderer->scale.y = 1.0f;
- renderer->dpi_scale.x = 1.0f;
- renderer->dpi_scale.y = 1.0f;
+ /* let app/user override batching decisions. */
+ if (renderer->always_batch) {
+ batching = SDL_TRUE;
+ } else if (SDL_GetHint(SDL_HINT_RENDER_BATCHING)) {
+ batching = SDL_GetHintBoolean(SDL_HINT_RENDER_BATCHING, SDL_TRUE);
+ }
- /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
- renderer->render_command_generation = 1;
+ renderer->batching = batching;
+ renderer->magic = &renderer_magic;
+ renderer->window = window;
+ renderer->target_mutex = SDL_CreateMutex();
+ renderer->scale.x = 1.0f;
+ renderer->scale.y = 1.0f;
+ renderer->dpi_scale.x = 1.0f;
+ renderer->dpi_scale.y = 1.0f;
- if (window && renderer->GetOutputSize) {
- int window_w, window_h;
- int output_w, output_h;
- if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
- SDL_GetWindowSize(renderer->window, &window_w, &window_h);
- renderer->dpi_scale.x = (float)window_w / output_w;
- renderer->dpi_scale.y = (float)window_h / output_h;
- }
- }
+ /* new textures start at zero, so we start at 1 so first render doesn't flush by accident. */
+ renderer->render_command_generation = 1;
- if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
- renderer->hidden = SDL_TRUE;
- } else {
- renderer->hidden = SDL_FALSE;
+ if (window && renderer->GetOutputSize) {
+ int window_w, window_h;
+ int output_w, output_h;
+ if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
+ SDL_GetWindowSize(renderer->window, &window_w, &window_h);
+ renderer->dpi_scale.x = (float)window_w / output_w;
+ renderer->dpi_scale.y = (float)window_h / output_h;
}
+ }
+
+ if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
+ renderer->hidden = SDL_TRUE;
+ } else {
+ renderer->hidden = SDL_FALSE;
+ }
- SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
+ SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
- SDL_RenderSetViewport(renderer, NULL);
+ SDL_RenderSetViewport(renderer, NULL);
- SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
+ SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
+
+ SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
+ "Created renderer: %s", renderer->info.name);
- SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
- "Created renderer: %s", renderer->info.name);
- }
return renderer;
+
+error:
+ return NULL;
+
#else
SDL_SetError("SDL not built with rendering support");
return NULL;