go-sdl2
go-sdl2 copied to clipboard
window.UpdateSurface() errors out on wayland
I'm using sdl2 2.0.20 and go-sdl2 0.4.12. I believe the bug was introduced by the new sdl2 version, as the code worked fine around 2.0.16 with go-sdl2 0.4.10 a few months ago.
The following minimal example breaks with error Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface
:
package main
import (
"github.com/veandco/go-sdl2/sdl"
)
func main() {
if err := sdl.Init(sdl.INIT_EVENTS|sdl.INIT_VIDEO); err != nil {
panic(err)
}
defer sdl.Quit()
window, _ := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED, 800, 600, 0)
defer window.Destroy()
sdlSurface, err := window.GetSurface()
if err != nil {
panic(err)
}
sdlSurface.FillRect(nil, 0)
running := true
for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
running = false
}
if err := window.UpdateSurface(); err != nil { // this doesn't work anymore
println(err.Error())
}
}
sdl.Delay(30)
}
}
(calling getsurface just before the window.updatesurface removes the warning but gives a black screen that panics soon after)
Hi @yory8! I couldn't reproduce the issue using SDL2 2.0.20 and go-sdl2 v0.4.12 on my Fedora Linux, macOS Monterey (M1), and Windows 10. Could you help me reproduce it by specifying which platform you are running it on and how you got SDL2? Any extra information that could be related to this would also help.
Thanks. I'm using it on Arch Linux, with the system's sdl2, using wayland (sway wm). Unfortunately I had paused working on my code for several months, so I'm unable to say when exactly it started breaking, and why (I managed to try sdl2 2.0.18 and it breaks too, but I cannot go any further because of incompatible dependencies)
Ahh you're using Wayland. I'm not too familiar with it but perhaps setting the environment variable SDL_VIDEODRIVER=wayland
would make it work? Maybe running a command like:
SDL_VIDEODRIVER=wayland go run main.go
If not, I will try to set up the same environment on one of my spare laptops or VMs to see if I can reproduce it.
Doesn't work (was already using wayland), but it works if I do SDL_VIDEODRIVER=x11 go run main.go
so it seems to be some change in wlroots (the wayland implementation used by sway).