hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.52k stars 641 forks source link

internal/glfw: rare crash at setting an icon on macOS #2474

Open hajimehoshi opened 1 year ago

hajimehoshi commented 1 year ago

Ebitengine Version

v2.5.0-alpha.7

Operating System

Go Version (go version)

go version go1.19.2 darwin/amd64

What steps will reproduce the problem?

Just launch an application.

What is the expected result?

panic: NotInitialized: The GLFW library is not initialized

goroutine 1 [running, locked to thread]:
github.com/go-gl/glfw/v3.3/glfw.acceptError({0x0, 0x0, 0xc00005ef00?})
    /Users/daigosato/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20221017161538-93cebf72946b/error.go:174 +0x1d9
github.com/go-gl/glfw/v3.3/glfw.panicError(...)
    /Users/daigosato/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20221017161538-93cebf72946b/error.go:185
github.com/go-gl/glfw/v3.3/glfw.(*Window).GetMonitor(0x1000067f1?)
    /Users/daigosato/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20221017161538-93cebf72946b/window.go:662 +0x2b
github.com/hajimehoshi/ebiten/v2/internal/glfw.(*Window).GetMonitor(...)
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/glfw/glfw_notwindows.go:128
github.com/hajimehoshi/ebiten/v2/internal/ui.(*userInterfaceImpl).isFullscreen(0x100d62540)
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/ui/ui_glfw.go:537 +0x33
github.com/hajimehoshi/ebiten/v2/internal/ui.(*userInterfaceImpl).loop.func3.1()
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/ui/ui_glfw.go:1156 +0x5c
github.com/hajimehoshi/ebiten/v2/internal/thread.(*OSThread).Loop.func1(0xc01b217e08?, 0xc01b217df8?)
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/thread/thread.go:54 +0x53
github.com/hajimehoshi/ebiten/v2/internal/thread.(*OSThread).Loop(0xc000123998)
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/thread/thread.go:55 +0x2e
github.com/hajimehoshi/ebiten/v2/internal/ui.(*userInterfaceImpl).Run(0x100d62540, {0x10082c668?, 0xc000240bd0})
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/internal/ui/run_notsinglethread.go:52 +0x231
github.com/hajimehoshi/ebiten/v2.RunGame({0x1008293a8, 0xc000001680})
    /Users/daigosato/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.0-alpha.7/run.go:233 +0x9d
main.main()
    /Users/daigosato/Development/odencat/rpgsnack/rpgsnack-runtime/main.go:127 +0x1d9

What happens instead?

No crash

Anything else you feel useful to add?

The issue is very rare and there is no stable way to reproduce this.

TotallyGamerJet commented 1 year ago

Which go Version are u using? And the expected is no crash right?

hajimehoshi commented 1 year ago

(EDITED: NVM, I was misunderstanding)

hajimehoshi commented 1 year ago

Which go Version are u using?

1.19.2.

And the expected is no crash right?

Right.

TotallyGamerJet commented 1 year ago

Yeah I wouldn't really expect gotip branch to work since it doesn't play nicely with goroutines. There must be a reason it thinks that we are in Cgo when we aren't yet. I need to look into this further.

Fortunately, ebitengine won't flat at break in Go 1.20. Only -race when CGO_ENABLED=0 so a temporary fix is to just have them enable Cgo when using race which is already required. Plus ebitengine uses Cgo for glfw so it's okay for now.

hajimehoshi commented 1 year ago

Hmm this is a very mysterious error and this should never happen in theory.

TotallyGamerJet commented 1 year ago

I came across this golang/go#57263 issue which may relate.