Fix crash when GL_LoadFunctions()/GLES2_LoadFunctions() fails https://bugzilla.libsdl.org/show_bug.cgi?id=4350 We can't safely call GL_DestroyRenderer() until GL_LoadFunctions() succeeds because we will be missing functions that we try to use when activating the renderer for destruction if we have an GL context.
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
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index f3e8326..09db12d 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -420,7 +420,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
- GL_DestroyRenderer(renderer);
+ SDL_free(renderer);
SDL_OutOfMemory();
goto error;
}
@@ -455,16 +455,21 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
- GL_DestroyRenderer(renderer);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
- GL_DestroyRenderer(renderer);
+ SDL_GL_DeleteContext(data->context);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}
if (GL_LoadFunctions(data) < 0) {
- GL_DestroyRenderer(renderer);
+ SDL_GL_DeleteContext(data->context);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index fe51b9a..f21a957 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -2122,7 +2122,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
data = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
if (!data) {
- GLES2_DestroyRenderer(renderer);
+ SDL_free(renderer);
SDL_OutOfMemory();
goto error;
}
@@ -2134,16 +2134,21 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
/* Create an OpenGL ES 2.0 context */
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
- GLES2_DestroyRenderer(renderer);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
- GLES2_DestroyRenderer(renderer);
+ SDL_GL_DeleteContext(data->context);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}
if (GLES2_LoadFunctions(data) < 0) {
- GLES2_DestroyRenderer(renderer);
+ SDL_GL_DeleteContext(data->context);
+ SDL_free(renderer);
+ SDL_free(data);
goto error;
}