Skip to content

Commit

Permalink
ffi/sdl: ensure correct order of SDL_DestroyRenderer followed by SDL_…
Browse files Browse the repository at this point in the history
…Quit (koreader#1730)

When running in Wayland, calling SDL_DestroyRenderer after SDL_Quit can cause a segmentation fault.

Fixes <koreader/koreader#11371>.
  • Loading branch information
Frenzie authored Jan 18, 2024
1 parent 3e94c06 commit 6599e1f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
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 = ffi.gc(SDL.SDL_CreateRenderer(S.screen, -1, 0), SDL.SDL_DestroyRenderer)
S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0)
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/framebuffer_SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function framebuffer:setWindowIcon(icon)
end

function framebuffer:close()
SDL.SDL.SDL_DestroyRenderer(SDL.renderer)
SDL.SDL.SDL_Quit()
end

Expand Down

0 comments on commit 6599e1f

Please sign in to comment.