gcla / gowid

Compositional widgets for terminal user interfaces, written in Go, inspired by urwid.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Application crashes sometimes in RedrawTerminal

Peter2121 opened this issue · comments

...with the following error in console:

panic: interface conversion: gowid.RenderFixed is not gowid.IRenderWithWeight: missing method Weight
goroutine 1 [running]:
github.com/gcla/gowid/widgets/columns.widgetWidthsExt({0x828115490, 0xc000177130}, {0xc0015141e0, 0xa, 0xa}, {0xc001514280, 0xa, 0xa}, {0x264e20, 0xc000a4a080}, ...)
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:550 +0xc98
github.com/gcla/gowid/widgets/columns.WidgetWidths({0x2ccda0, 0xc000177130}, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:430 +0x19a
github.com/gcla/gowid/widgets/columns.(*Widget).WidgetWidths(0xc000177130, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:225 +0x8e
github.com/gcla/gowid/widgets/columns.RenderSubWidgets({0x2d2488, 0xc000177130}, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:665 +0x156
github.com/gcla/gowid/widgets/columns.(*Widget).RenderSubWidgets(0xc000177130, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:214 +0x8e
github.com/gcla/gowid/widgets/columns.Render({0x2d2488, 0xc000177130}, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:620 +0x13c
github.com/gcla/gowid/widgets/columns.(*Widget).Render(0xc000177130, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/columns/columns.go:210 +0x78
github.com/gcla/gowid/widgets/pile.RenderSubwidgets.func1({0x2cdd98, 0xc0001c98e0}, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:495 +0x72
github.com/gcla/gowid/widgets/pile.BoxMakerFunc.MakeBox(0x28cfa0, {0x2cdd98, 0xc0001c98e0}, {0x264e20, 0xc000a4a080}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:516 +0x84
github.com/gcla/gowid/widgets/pile.RenderBoxMaker({0x2d2550, 0xc0001d4280}, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500}, {0x2ca6e0, ...})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:583 +0x710
github.com/gcla/gowid/widgets/pile.(*Widget).RenderBoxMaker(0xc0001d4280, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500}, {0x2ca6e0, 0x28cfa0})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:219 +0xbf
github.com/gcla/gowid/widgets/pile.RenderSubwidgets({0x2d2550, 0xc0001d4280}, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:498 +0xba
github.com/gcla/gowid/widgets/pile.(*Widget).RenderSubWidgets(0xc0001d4280, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:211 +0x8e
github.com/gcla/gowid/widgets/pile.Render({0x2d2550, 0xc0001d4280}, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:444 +0xc2
github.com/gcla/gowid/widgets/pile.(*Widget).Render(0xc0001d4280, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:198 +0x78
github.com/gcla/gowid/widgets/pile.RenderSubwidgets.func1({0x2cdd98, 0xc0001c99a0}, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:495 +0x72
github.com/gcla/gowid/widgets/pile.BoxMakerFunc.MakeBox(0x28cfa0, {0x2cdd98, 0xc0001c99a0}, {0x264e20, 0xc000a4a050}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:516 +0x84
github.com/gcla/gowid/widgets/pile.RenderBoxMaker({0x2d2550, 0xc0001d4300}, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500}, {0x2ca6e0, ...})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:658 +0xba2
github.com/gcla/gowid/widgets/pile.(*Widget).RenderBoxMaker(0xc0001d4300, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500}, {0x2ca6e0, 0x28cfa0})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:219 +0xbf
github.com/gcla/gowid/widgets/pile.RenderSubwidgets({0x2d2550, 0xc0001d4300}, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:498 +0xba
github.com/gcla/gowid/widgets/pile.(*Widget).RenderSubWidgets(0xc0001d4300, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, 0x0, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:211 +0x8e
github.com/gcla/gowid/widgets/pile.Render({0x2d2550, 0xc0001d4300}, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:444 +0xc2
github.com/gcla/gowid/widgets/pile.(*Widget).Render(0xc0001d4300, {0x264e20, 0xc000a4a000}, {0x0, 0x0}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/pile/pile.go:198 +0x78
github.com/gcla/gowid/widgets/overlay.Render({0x2d0780, 0xc00155ed20}, {0x264e20, 0xc000a4a000}, {0x1, 0x1}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/overlay/overlay.go:304 +0xf9
github.com/gcla/gowid/widgets/overlay.(*Widget).Render(0xc00155ed20, {0x264e20, 0xc000a4a000}, {0x1, 0x1}, {0x2d2618, 0xc000194500})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/widgets/overlay/overlay.go:226 +0x78
github.com/gcla/gowid.RenderRoot({0x2ce000, 0xc0001c9a20}, 0xc000194500)
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/support.go:835 +0xfa
github.com/gcla/gowid.(*App).RedrawTerminal(0xc000194500)
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/app.go:719 +0x3d
github.com/gcla/gowid.(*App).HandleTCellEvent(0xc000194500, {0x255280, 0xc000933e40}, {0x2ca900, 0x869498})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/app.go:501 +0xadd
github.com/gcla/gowid.(*App).handleEvents(0xc000194500, {0x2ca900, 0x869498})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/app.go:675 +0x145
github.com/gcla/gowid.(*App).MainLoop(0xc000194500, {0x2ca900, 0x869498})
        /root/go/pkg/mod/github.com/gcla/gowid@v1.4.1-0.20220717013040-1d7a75b6f5cb/app.go:656 +0x129
main.main()
        /root/cbsd-tui/cbsd-tui.go:1265 +0x32b2

cbsd-tui.go:1265 is just app.MainLoop(handler{})

The problem arrives when I update a dialog (with edit widget inside) in cycle showing the output of a command as it comes. The dialog is created as follows:

func CreateActionsLogDialog(editWidget *edit.Widget) *dialog.Widget {
	baheight := cbsdJailConsole.Height()
	ba := boxadapter.New(
		styled.New(
			NewEditWithScrollbar(editWidget),
			gowid.MakePaletteRef("white"),
		),
		baheight,
	)
	actionlogdialog := dialog.New(
		framed.NewUnicode(ba),
		dialog.Options{
			Buttons:         []dialog.Button{dialog.CloseD},
			Modal:           true,
			NoShadow:        true,
			TabToButtons:    true,
			BackgroundStyle: gowid.MakePaletteRef("bluebg"),
			BorderStyle:     gowid.MakePaletteRef("dialog"),
			ButtonStyle:     gowid.MakePaletteRef("white-focus"),
			FocusOnWidget:   true,
		},
	)
	return actionlogdialog
}

NewEditWithScrollbar is taken from editor example.

I suppose that there are some race conditions somewhere...

Hi @Peter2121 - I'm sorry for the slow support lately.

This backtrace has me puzzled. Is there any chance you have local modifications to the columns widget? The reason I ask is that at line 550 in columns.go, this cast is failing:

for i := 0; i < lenw; i++ {
	// Can only be weight here if !helper[i] ; but not sufficient for it to be eligible
	if !widthHelper[i] {
		cols := int(((float32(dims[i].(gowid.IRenderWithWeight).Weight()) / float32(totalWeight)) * float32(colsToDivideUp)) + 0.5)     // <--- cast to IRenderWithWeight fails
                ...
        }
   ...
}

But at line 475, prior to the failure, this code runs:

for i := 0; i < lenw; i++ {
   switch w2 := dims[i].(type) {
   case gowid.IRenderFixed:
           ...
   	widthHelper[i] = true     // <--- puzzle
           ...
   }
   ...
}

The error indicates an invalid cast from gowid.RenderFixed to gowid.IRenderWithWeight.

I've just checked the sources of the module github.com/gcla/gowid v1.4.1-0.20220717013040-1d7a75b6f5cb declared in go.mod - there is the same code in columns.go. So, for sure, there are no local modifications here.

I think, the important point here is that it works correctly in 95% of cases and crashes sometimes.