nelsam / vidar

vidar is a highly experimental Go editor, written in Go, using gxui
The Unlicense
50 stars 7 forks source link

panic: Cannot call Relayout() while in LayoutChildren when collapsing(hiding) elements of the toc tree. #152

Closed Kvaz1r closed 5 years ago

Kvaz1r commented 5 years ago

Description

panic: Cannot call Relayout() while in LayoutChildren when collapsing(hiding) elements of the toc tree.

Steps to reproduce

p1

Expected behavior

Hiding of elements

Actual behavior

panic

Stack trace

panic: Cannot call Relayout() while in LayoutChildren

goroutine 4 [running]:
github.com/nelsam/gxui/mixins/parts.(*Layoutable).Relayout(0xc0424e6d90)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:71 +0xaf
github.com/nelsam/gxui/mixins.(*ScrollLayout).SetScrollOffset(0xc0424e6c00, 0x0, 0xbc, 0xf5b2c0)
    E:/gopath/src/github.com/nelsam/gxui/mixins/scroll_layout.go:107 +0x24f
github.com/nelsam/gxui/mixins.(*ScrollLayout).LayoutChildren(0xc0424e6c00)
    E:/gopath/src/github.com/nelsam/gxui/mixins/scroll_layout.go:84 +0x3b2
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb3dda0, 0xc0424e6c00)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc0424e6d90, 0xb4, 0x13c)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui.(*Child).Layout(0xc04272b5a0, 0x0, 0xa2, 0xb4, 0x1de)
    E:/gopath/src/github.com/nelsam/gxui/container.go:50 +0x69
github.com/nelsam/gxui/mixins.(*SplitterLayout).LayoutChildren(0xc0424de000)
    E:/gopath/src/github.com/nelsam/gxui/mixins/splitter_layout.go:88 +0x297
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb3b160, 0xc0424de000)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc0424de190, 0xb4, 0x1de)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui/mixins/parts.(*LinearLayout).LayoutChildren(0xc042379060)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/linear_layout.go:45 +0x2bc
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb43320, 0xc042378e00)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc042378f90, 0xd8, 0x1de)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui/mixins/parts.(*LinearLayout).LayoutChildren(0xc042137ae0)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/linear_layout.go:45 +0x2bc
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb413a0, 0xc042137880)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc042137a10, 0x30c, 0x1de)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui/mixins/parts.(*LinearLayout).LayoutChildren(0xc042140b60)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/linear_layout.go:45 +0x2bc
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb3e360, 0xc042140900)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc042140a90, 0x30c, 0x1f4)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui/mixins/parts.(*LinearLayout).LayoutChildren(0xc042140560)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/linear_layout.go:45 +0x2bc
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb3e360, 0xc042140300)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc042140490, 0x30c, 0x206)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/vidar/commander.(*Commander).LayoutChildren(0xc042137c00)
    E:/gopath/src/github.com/nelsam/vidar/commander/commander.go:104 +0x148
github.com/nelsam/gxui/mixins/parts.callLayoutChildrenIfSupported(0xb40760, 0xc042137c00)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/utils.go:14 +0x74
github.com/nelsam/gxui/mixins/parts.(*Layoutable).SetSize(0xc042137d90, 0x30c, 0x206)
    E:/gopath/src/github.com/nelsam/gxui/mixins/parts/layoutable.go:62 +0x97
github.com/nelsam/gxui.(*Child).Layout(0xc0422ee7e0, 0xa, 0xa, 0x316, 0x210)
    E:/gopath/src/github.com/nelsam/gxui/container.go:50 +0x69
github.com/nelsam/gxui/mixins.(*Window).LayoutChildren(0xc04219ab40)
    E:/gopath/src/github.com/nelsam/gxui/mixins/window.go:154 +0x193
github.com/nelsam/gxui/mixins.(*Window).update(0xc04219ab40)
    E:/gopath/src/github.com/nelsam/gxui/mixins/window.go:79 +0x92
github.com/nelsam/gxui/mixins.(*Window).(github.com/nelsam/gxui/mixins.update)-fm()
    E:/gopath/src/github.com/nelsam/gxui/mixins/window.go:63 +0x31
github.com/nelsam/gxui/drivers/gl.(*driver).applicationLoop(0xc042234050)
    E:/gopath/src/github.com/nelsam/gxui/drivers/gl/driver.go:141 +0x2b
created by github.com/nelsam/gxui/drivers/gl.StartDriver
    E:/gopath/src/github.com/nelsam/gxui/drivers/gl/driver.go:84 +0x3bf
nelsam commented 5 years ago

It took me a long time to reproduce this, but I did finally get it. The LayoutChildren call in ScrollLayout (used by the ProjectTree) will call SetScrollOffset, which will call Relayout if the change in the size of the children causes the scroll offset to change. You have to have scrolled down in the ProjectTree, then minimized some elements of the tree until there is empty space below the last elements. In this case, LayoutChildren will try to scroll using SetScrollOffset to fill up that empty space. SetScrollOffset will see that the offset changed and try to call Relayout. Relayout will discover that it's already in LayoutChildren and panic.

nelsam/gxui#17 solves it for me.