splitLayout sometimes crashes while resizing window.
Hi there!
demo code
package main
import (
g "github.com/AllenDang/giu"
)
var sashPos float32 = 80
func loop() {
g.Window("wnd").Size(80, 80).Layout(
g.SplitLayout(g.DirectionHorizontal, &sashPos,
g.Layout{
g.Label("Test1"),
},
g.Layout{
g.Label("Test2"),
},
),
)
}
func main() {
w := g.NewMasterWindow("Splitter", 640, 480, 0)
w.Run(loop)
}
panic message
main: imgui_widgets.cpp:731: bool ImGui::InvisibleButton(const char*, const ImVec2&, ImGuiButtonFlags): Assertion `size_arg.x != 0.0f && size_arg.y != 0.0f' failed.
SIGABRT: abort
PC=0x7f4cc779f2a2 m=0 sigcode=18446744073709551610
signal arrived during cgo execution
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x5e96a0, 0xc0000cb9a0)
/usr/local/go/src/runtime/cgocall.go:156 +0x5c fp=0xc0000cb978 sp=0xc0000cb940 pc=0x485f9c
github.com/AllenDang/imgui-go._Cfunc_iggInvisibleButton(0x304e170, 0xc000298ef0)
_cgo_gotypes.go:4084 +0x4c fp=0xc0000cb9a0 sp=0xc0000cb978 pc=0x550a6c
github.com/AllenDang/imgui-go.InvisibleButton({0xc000298e40, 0x200000003}, {0x40800000, 0x0})
/home/username/git/d2/me/giu/vendor/github.com/AllenDang/imgui-go/imgui.go:392 +0x8d fp=0xc0000cb9e0 sp=0xc0000cb9a0 pc=0x55886d
github.com/AllenDang/giu.(*VSplitterWidget).Build(0xc0002886e0)
/home/username/git/d2/me/giu/Widgets.go:2137 +0xc5 fp=0xc0000cba70 sp=0xc0000cb9e0 pc=0x5e5e45
github.com/AllenDang/giu.(*RowWidget).Build.func1({0x8ba160, 0xc0002886e0})
/home/username/git/d2/me/giu/Widgets.go:59 +0x159 fp=0xc0000cba98 sp=0xc0000cba70 pc=0x5e5339
github.com/AllenDang/giu.Layout.Range({0xc000280f60, 0x3, 0x552265}, 0xc00028b0b0)
/home/username/git/d2/me/giu/Layout.go:48 +0x9c fp=0xc0000cbaf0 sp=0xc0000cba98 pc=0x5e2bfc
github.com/AllenDang/giu.(*RowWidget).Build(0xc0002858c0)
/home/username/git/d2/me/giu/Widgets.go:41 +0x85 fp=0xc0000cbb28 sp=0xc0000cbaf0 pc=0x5e51a5
github.com/AllenDang/giu.Layout.Build({0xc0000cbc30, 0x1, 0x8ba500})
/home/username/git/d2/me/giu/Layout.go:28 +0x58 fp=0xc0000cbb50 sp=0xc0000cbb28 pc=0x5e2b18
github.com/AllenDang/giu.(*SplitLayoutWidget).Build(0xc00028c410)
/home/username/git/d2/me/giu/SplitLayout.go:130 +0x5fd fp=0xc0000cbc80 sp=0xc0000cbb50 pc=0x5e4b3d
github.com/AllenDang/giu.Layout.Build({0xc0002886c0, 0x2, 0x0})
/home/username/git/d2/me/giu/Layout.go:28 +0x58 fp=0xc0000cbca8 sp=0xc0000cbc80 pc=0x5e2b18
github.com/AllenDang/giu.(*WindowWidget).Layout(0xc0000cbd90, {0xc0000cbd80, 0x1, 0x1})
/home/username/git/d2/me/giu/Window.go:139 +0x23e fp=0xc0000cbd30 sp=0xc0000cbca8 pc=0x5e62fe
main.loop()
/home/username/git/d2/me/giu/examples/split-layout-bug/main.go:8 +0x2a5 fp=0xc0000cbdd8 sp=0xc0000cbd30 pc=0x5e6fe5
github.com/AllenDang/giu.(*MasterWindow).render(0xc00007e000)
/home/username/git/d2/me/giu/MasterWindow.go:192 +0xa5 fp=0xc0000cbe48 sp=0xc0000cbdd8 pc=0x5e3a65
github.com/AllenDang/giu.(*MasterWindow).run.func1()
/home/username/git/d2/me/giu/MasterWindow.go:210 +0x48 fp=0xc0000cbe80 sp=0xc0000cbe48 pc=0x5e3cc8
github.com/faiface/mainthread.Call.func1()
/home/username/git/d2/me/giu/vendor/github.com/faiface/mainthread/mainthread.go:63 +0x26 fp=0xc0000cbeb0 sp=0xc0000cbe80 pc=0x55cde6
github.com/faiface/mainthread.Run(0xc00000e4c8)
/home/username/git/d2/me/giu/vendor/github.com/faiface/mainthread/mainthread.go:44 +0xc9 fp=0xc0000cbf28 sp=0xc0000cbeb0 pc=0x55cba9
github.com/AllenDang/giu.(*MasterWindow).Run(0xc00007e000, 0x890580)
/home/username/git/d2/me/giu/MasterWindow.go:283 +0x72 fp=0xc0000cbf48 sp=0xc0000cbf28 pc=0x5e3d72
main.main()
/home/username/git/d2/me/giu/examples/split-layout-bug/main.go:22 +0x3d fp=0xc0000cbf80 sp=0xc0000cbf48 pc=0x5e703d
runtime.main()
/usr/local/go/src/runtime/proc.go:255 +0x227 fp=0xc0000cbfe0 sp=0xc0000cbf80 pc=0x4b7fa7
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc0000cbfe8 sp=0xc0000cbfe0 pc=0x4e39a1
goroutine 5 [chan receive]:
github.com/faiface/mainthread.Call(0xc000280e70)
/home/username/git/d2/me/giu/vendor/github.com/faiface/mainthread/mainthread.go:66 +0xb1
github.com/AllenDang/giu.(*MasterWindow).run(0xc00007e000)
/home/username/git/d2/me/giu/MasterWindow.go:208 +0x87
github.com/AllenDang/giu.(*MasterWindow).Run.func1()
/home/username/git/d2/me/giu/MasterWindow.go:288 +0x4b
github.com/faiface/mainthread.Run.func1()
/home/username/git/d2/me/giu/vendor/github.com/faiface/mainthread/mainthread.go:37 +0x26
created by github.com/faiface/mainthread.Run
/home/username/git/d2/me/giu/vendor/github.com/faiface/mainthread/mainthread.go:36 +0xbd
rax 0x0
rbx 0x7f4cc7615740
rcx 0x7f4cc779f2a2
rdx 0x0
rdi 0x2
rsi 0x7ffe40acb370
rbp 0x7f4cc79278f0
rsp 0x7ffe40acb370
r8 0x0
r9 0x7ffe40acb370
r10 0x8
r11 0x246
r12 0x8e8ed5
r13 0x2db
r14 0x8e6fe8
r15 0xef
rip 0x7f4cc779f2a2
rflags 0x246
cs 0x33
fs 0x0
gs 0x0
exit status 2
to reproduce
- run the demo
- play with window resizing (catch bottom-right corner)
- app will crash

look arrow, wrong syntax (smile)
@gadmin88 the syntax have changed since https://github.com/AllenDang/giu/pull/486 , the new code example should look as follows
package main
import (
g "github.com/AllenDang/giu"
)
var sashPos float32 = 80
func loop() {
g.Window("wnd").Size(80, 80).Layout(
g.SplitLayout(g.DirectionHorizontal, &sashPos,
g.Layout{
g.Label("Test1"),
},
g.Layout{
g.Label("Test2"),
},
),
)
}
func main() {
w := g.NewMasterWindow("Splitter", 640, 480, 0)
w.Run(loop)
}
and it still crashes

@gadmin88 you're using wrong version! since #486 pointer is required. However it is off-topic here
@gadmin88 you're using wrong version! since #486 pointer is required. However it is off-topic here


Just tested for you, the GIT-Master Version, it dit NOT crash 👍
Take a look at this part: Assertion `size_arg.x != 0.0f && size_arg.y != 0.0f' failed.
ok, I think I understand what's going on here. VSplitter has the following in its Size method:
aw, ah := GetAvailableRegion()
// ...
if height == 0 {
v.height = ah
} else {
v.height = height
}
and sometimes height == 0 && availableHeight === 0 this causes panic