Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.UpdateSurface() errors out on wayland #506

Open
ghost opened this issue Feb 5, 2022 · 5 comments
Open

window.UpdateSurface() errors out on wayland #506

ghost opened this issue Feb 5, 2022 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 5, 2022

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)

@veeableful
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented Feb 7, 2022

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)

@veeableful
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented Feb 7, 2022

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).

@ghost ghost changed the title window.UpdateSurface() errors out window.UpdateSurface() errors out on wayland Feb 7, 2022
@Grammercy
Copy link

Hi, this is happening to me on X11, but it only happens when I run sdl.PollEvent(), does removing event polling fix the issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants