From 40d85109acb676686de0db0ced7209e24bc9fc7f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 30 Aug 2024 07:00:46 -0700
Subject: [PATCH] Fixed crash when using the dummy video driver
The higher level code will clean up the renderer if initialization fails.
---
src/render/sdlgpu/SDL_render_gpu.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/render/sdlgpu/SDL_render_gpu.c b/src/render/sdlgpu/SDL_render_gpu.c
index 6a6aa9dcdfb07..6cc655b7ed7e3 100644
--- a/src/render/sdlgpu/SDL_render_gpu.c
+++ b/src/render/sdlgpu/SDL_render_gpu.c
@@ -1190,7 +1190,7 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
if (renderer->output_colorspace != SDL_COLORSPACE_SRGB) {
// TODO
SDL_SetError("Unsupported output colorspace");
- goto error;
+ return false;
}
bool debug = SDL_GetBooleanProperty(create_props, SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOL, false);
@@ -1207,24 +1207,24 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
data->device = SDL_CreateGPUDeviceWithProperties(create_props);
if (!data->device) {
- goto error;
+ return false;
}
if (!GPU_InitShaders(&data->shaders, data->device)) {
- goto error;
+ return false;
}
if (!GPU_InitPipelineCache(&data->pipeline_cache, data->device)) {
- goto error;
+ return false;
}
// XXX what's a good initial size?
if (!InitVertexBuffer(data, 1 << 16)) {
- goto error;
+ return false;
}
if (!InitSamplers(data)) {
- goto error;
+ return false;
}
renderer->SupportsBlendMode = GPU_SupportsBlendMode;
@@ -1251,7 +1251,7 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
renderer->name = GPU_RenderDriver.name;
if (!SDL_ClaimGPUWindow(data->device, window)) {
- goto error;
+ return false;
}
data->swapchain.composition = SDL_GPU_SWAPCHAINCOMPOSITION_SDR;
@@ -1286,14 +1286,10 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
SDL_GetWindowSizeInPixels(window, &w, &h);
if (!CreateBackbuffer(data, w, h, SDL_GetGPUSwapchainTextureFormat(data->device, window))) {
- goto error;
+ return false;
}
return true;
-
-error:
- GPU_DestroyRenderer(renderer);
- return false;
}
SDL_RenderDriver GPU_RenderDriver = {