veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

impossible type switch case: sdl.QuitEvent #585

Closed n-i-x closed 4 months ago

n-i-x commented 6 months ago

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
            }
        }
    }
veeableful commented 6 months ago

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?

FandaLas commented 5 months ago

I had the same issue.

After changing to pointer

case *sdl.QuitEvent:

it works.

veeableful commented 5 months ago

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

FandaLas commented 5 months ago

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.