cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.31k stars 71 forks source link

Crash when getting monitors #947

Open kkoreilly opened 2 months ago

kkoreilly commented 2 months ago

Describe the bug

Probably due to a monitor being plugged in while the app was running.

How to reproduce

Try plugging a monitor in while an app is running (probably one that it will switch to as the main monitor).

Example code

No response

Relevant output

Platform: MacOS
System platform: MacOS
App version: v0.0.9-186-g51e6d9742
Core version: v0.0.9-186-g51e6d9742
Time: 2024-04-04 14:55:17

panic: runtime error: index out of range [2] with length 2

goroutine 1 [running, locked to thread]:
runtime/debug.Stack()
    /opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/debug/stack.go:24 +0x64
cogentcore.org/core/goosi.HandleRecoverBase({0x106492a40, 0x1401fe7cdb0})
    /Users/kaioreilly/cogent/core/goosi/recover.go:49 +0x38
cogentcore.org/core/gi.HandleRecover({0x106492a40, 0x1401fe7cdb0})
    /Users/kaioreilly/cogent/core/gi/recover.go:32 +0x48
cogentcore.org/core/gi.Wait.func1()
    /Users/kaioreilly/cogent/core/gi/renderwin.go:35 +0x34
panic({0x106492a40?, 0x1401fe7cdb0?})
    /opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/panic.go:770 +0x124
cogentcore.org/core/goosi/driver/desktop.(*App).GetScreens(0x106f145e0)
    /Users/kaioreilly/cogent/core/goosi/driver/desktop/screen.go:80 +0x1464
cogentcore.org/core/goosi/driver/desktop.(*App).MonitorChange(0x106f145e0, 0x106425420?, 0x1400004db01?)
    /Users/kaioreilly/cogent/core/goosi/driver/desktop/screen.go:39 +0xf8
github.com/go-gl/glfw/v3.3/glfw.goMonitorCB(...)
    /Users/kaioreilly/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20240307211618-a69d953ea142/monitor.go:52
github.com/go-gl/glfw/v3.3/glfw._Cfunc_glfwWaitEvents()
    _cgo_gotypes.go:2455 +0x30
github.com/go-gl/glfw/v3.3/glfw.WaitEvents()
    /Users/kaioreilly/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20240307211618-a69d953ea142/window.go:949 +0x1c
cogentcore.org/core/goosi/driver/desktop.(*App).MainLoop(0x106f145e0)
    /Users/kaioreilly/cogent/core/goosi/driver/desktop/app.go:71 +0x10c
cogentcore.org/core/gi.Wait()
    /Users/kaioreilly/cogent/core/gi/renderwin.go:41 +0x58
cogentcore.org/core/gi.(*Stage).Wait(...)
    /Users/kaioreilly/cogent/core/gi/stage.go:311
cogentcore.org/core/gi.(*Body).RunMainWindow(0x1400036c008?)
    /Users/kaioreilly/cogent/core/gi/mainstage.go:41 +0x38
main.main()
    /Users/kaioreilly/cogent/core/examples/demo/demo.go:49 +0x138

Platform

macOS