go-sdl2 icon indicating copy to clipboard operation
go-sdl2 copied to clipboard

impossible type switch case: sdl.QuitEvent

Open n-i-x opened this issue 1 year ago • 4 comments

Go version: go version go1.21.5 linux/amd64 Go-SDL2 version: v0.4.36 SDL2 version: 2.26.5+dfsg-1 OS: debian Architecture: amd64

When attempting to compile any of the examples, I get the following error:

./main.go:34:9: impossible type switch case: sdl.QuitEvent
        event (variable of type sdl.Event) cannot have dynamic type sdl.QuitEvent (method GetTimestamp has pointer receiver)

The code generating the error is:

running := true
	for running {
		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case sdl.QuitEvent:
				println("Quit")
				running = false
				break
			}
		}
	}

n-i-x avatar Dec 12 '23 01:12 n-i-x

Hi @n-i-x, did you use the example from the master branch which is for v0.5.x? If so, could you try the example used by the v0.4.x branch?

veeableful avatar Dec 12 '23 02:12 veeableful

I had the same issue.

After changing to pointer

case *sdl.QuitEvent:

it works.

FandaLas avatar Jan 10 '24 17:01 FandaLas

Hi @FandaLas, are you perhaps using the README of the master branch? In the stable version v0.4.x, we do use pointer.

veeableful avatar Jan 11 '24 03:01 veeableful

Hi @FandaLas, are you perhaps using the README of the master branch? In the stable version v0.4.x, we do use pointer.

Confirmed. My mistake.

FandaLas avatar Jan 11 '24 15:01 FandaLas