ebiten-imgui
ebiten-imgui copied to clipboard
panics within a Begin()->End() clause are partially suppressed
Issue
When running imgui code, anything that would cause a panic (e.g. indexing too high in a slice) will correctly cause the program to crash, but the real error message gets suppressed in favor of one from imgui.
A normal message after a panic looks like:
$ go run .
panic: runtime error: index out of range [1] with length 0
goroutine 44 [running]:
main.(*G).Update(0xc000079d30?)
/home/omustardo/go/src/github.com/omustardo/idle/experimentation/crash_demo/main.go:49 +0xa8
github.com/hajimehoshi/ebiten/v2.(*gameForUI).Update(0xc0000c22a0)
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/gameforui.go:142 +0x23
github.com/hajimehoshi/ebiten/v2/internal/ui.(*context).updateFrameImpl(0xc000216b00, {0xd586d8, 0xc0001c1200}, 0x1, 0x407f400000000000, 0x407f400000000000, 0x3ff0000000000000, 0xc0003c3348, 0x0)
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/context.go:148 +0x2be
github.com/hajimehoshi/ebiten/v2/internal/ui.(*context).updateFrame(0xc000216b00, {0xd586d8, 0xc0001c1200}, 0x407f400000000000, 0x407f400000000000, 0x3ff0000000000000, 0xc0003c3348)
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/context.go:73 +0x76
github.com/hajimehoshi/ebiten/v2/internal/ui.(*UserInterface).updateGame(0xc0003c3348)
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/ui_glfw.go:1452 +0x1a5
github.com/hajimehoshi/ebiten/v2/internal/ui.(*UserInterface).loopGame(0xc0003c3348)
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/ui_glfw.go:1409 +0x97
github.com/hajimehoshi/ebiten/v2/internal/ui.(*UserInterface).runMultiThread.func2()
/home/omustardo/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/run.go:67 +0x37
golang.org/x/sync/errgroup.(*Group).Go.func1()
/home/omustardo/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
/home/omustardo/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x96
exit status 2
Using the example code below, this is what results if the panic is in the scope of certain imgui calls:
$ go run .
File: /home/runner/work/cimgui-go/cimgui-go/cimgui/imgui/imgui.cpp, Line: 9932
exit status 1
If you go to the suggested line, the error message is: "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?", which is misleading at best.
Demo
This is easily reproducible with: https://gist.github.com/Omustardo/6f7446d958e9005357b631eaba995305
I didn't test too thoroughly, but it definitely occurs when there's a panic between a call to imgui.Begin()
and imgui.End()
. Ideally imgui wouldn't affect panics in code outside of its scope.
Relevant bits:
func (g *G) Update() error {
ebimgui.Update(1.0 / 60.0)
ebimgui.BeginFrame()
defer ebimgui.EndFrame()
// _ = []int{}[1] // uncommenting causes a panic in a goroutine
imgui.BeginV("Window", nil, 0)
//_ = []int{}[1] // uncommenting causes a crash in imgui.cpp, Line: 9932
imgui.Text("Hello World!")
//_ = []int{}[1] // uncommenting causes a crash in imgui.cpp, Line: 9932
imgui.End()
// _ = []int{}[1] // uncommenting causes a panic in a goroutine
return nil