Closed husio closed 3 years ago
Hi @husio, while I don't know why it segfaults exactly, I believe the issue is related to the mixing of software and hardware rendering.
If you want to use SDL_Surface (software) for rendering, you can omit sdl.Renderer
. If you want to use SDL_Renderer (hardware), you can set sdl.WINDOW_OPENGL
in sdl.CreateWindow()
and use renderer.FillRect()
for rendering instead.
I do not fully understand what was the issue with the code. What @veeableful wrote seem to help. Would it be helpful to add the information about not using sdl.Render
with software rendering to the documentation?
In the SDL2 documentation, window.GetSurface
is documented here: https://wiki.libsdl.org/SDL_GetWindowSurface.
It notes, "You may not combine this with 3D or the rendering API on this window."
The bottom of that page indicates it is in the Video API category.
So if we look at the API categories and select 2D Accelerated Rendering, we get the page https://wiki.libsdl.org/CategoryRender.
This page contains the API for sdl.CreateRenderer
here: https://wiki.libsdl.org/SDL_CreateRenderer.
Thus, using SDL_GetWindowSurface
and SDL_CreateRenderer
together is prohibited, or at least causes undefined behavior.
If you want a surface with the current properties of your window, you can try https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormat with https://wiki.libsdl.org/SDL_GetWindowPixelFormat as the format and https://wiki.libsdl.org/SDL_GetWindowSize as the size.
I have reported this issue so long ago that I no longer remember any details. I think it can be closed, although I really cannot tell if the root cause was solved (or valid).
Thanks, @husio. I will close it for now but feel free to comment here again if the same issue comes up!
When running the below example,
surface.FillRect(nil, 0)
occasionally panics withgo1.12.7 linux/amd64 github.com/veandco/go-sdl2 v0.3.1-0.20190809154531-da65661eff7f gcc (GCC) 9.1.0 SDL source-revision: SDL2:d3df61d8af architecture: x86_64-musl