Skip to content

Commit

Permalink
ffi/sdl: fix leaks on exit (#1667)
Browse files Browse the repository at this point in the history
Ensure the renderer is destroyed (which will also destroy its associated texture and window).
  • Loading branch information
benoit-pierre authored Oct 12, 2023
1 parent 99a4476 commit b6eb2fb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions ffi-cdecl/SDL2_0_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ cdecl_func(SDL_EnableScreenSaver)
cdecl_func(SDL_CreateWindow)
cdecl_func(SDL_GetWindowSize)
cdecl_func(SDL_CreateRenderer)
cdecl_func(SDL_DestroyRenderer)
cdecl_func(SDL_CreateWindowAndRenderer)
cdecl_func(SDL_GetRendererInfo)
cdecl_func(SDL_GetRendererOutputSize)
Expand Down
2 changes: 1 addition & 1 deletion ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function S.open(w, h, x, y)
-- What's even more curious is that we still only get a single SDL_WINDOWEVENT_MOVED on startup, except that way it's at the requested coordinates...
SDL.SDL_SetWindowPosition(S.screen, pos_x, pos_y)

S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0)
S.renderer = ffi.gc(SDL.SDL_CreateRenderer(S.screen, -1, 0), SDL.SDL_DestroyRenderer)
local output_w = ffi.new("int[1]", 0)
local output_h = ffi.new("int[1]", 0)
if SDL.SDL_GetRendererOutputSize(S.renderer, output_w, output_h) == 0 and tonumber(output_w[0]) ~= w then
Expand Down
1 change: 1 addition & 0 deletions ffi/SDL2_0_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ void SDL_EnableScreenSaver(void) __attribute__((visibility("default")));
SDL_Window *SDL_CreateWindow(const char *, int, int, int, int, Uint32) __attribute__((visibility("default")));
void SDL_GetWindowSize(SDL_Window *, int *, int *) __attribute__((visibility("default")));
SDL_Renderer *SDL_CreateRenderer(SDL_Window *, int, Uint32) __attribute__((visibility("default")));
void SDL_DestroyRenderer(SDL_Renderer *) __attribute__((visibility("default")));
int SDL_CreateWindowAndRenderer(int, int, Uint32, SDL_Window **, SDL_Renderer **) __attribute__((visibility("default")));
int SDL_GetRendererInfo(SDL_Renderer *, SDL_RendererInfo *) __attribute__((visibility("default")));
int SDL_GetRendererOutputSize(SDL_Renderer *, int *, int *) __attribute__((visibility("default")));
Expand Down

0 comments on commit b6eb2fb

Please sign in to comment.