Application crashes - "integer divide by zero"
Peter2121 opened this issue · comments
I built the following test app:
...
line1 := make([]gowid.IWidget, 0)
line2 := make([]gowid.IWidget, 0)
line3 := make([]gowid.IWidget, 0)
text1 := text.New("line1 item0")
text1h := holder.New(text1)
text1s := styled.NewWithRanges(text1h,
[]styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("test1notfocus")}}, []styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("streak")}})
btn1 := button.New(text1s)
line1 = append(line1, btn1)
for i := 1; i < 5; i++ {
txt := text.New(fmt.Sprintf("line1 item%d", i))
line1 = append(line1, txt)
}
text2 := text.New("line2 item0")
text2h := holder.New(text2)
text2s := styled.NewWithRanges(text2h,
[]styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("test1notfocus")}}, []styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("streak")}})
btn2 := button.New(text2s)
line2 = append(line2, btn2)
for i := 1; i < 5; i++ {
txt := text.New(fmt.Sprintf("line2 item%d", i))
line2 = append(line2, txt)
}
text3 := text.New("line3 item0")
text3h := holder.New(text3)
text3s := styled.NewWithRanges(text3h,
[]styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("test1notfocus")}}, []styled.AttributeRange{styled.AttributeRange{0, -1, gowid.MakePaletteRef("streak")}})
btn3 := button.New(text3s)
line3 = append(line3, btn3)
for i := 1; i < 5; i++ {
txt := text.New(fmt.Sprintf("line3 item%d", i))
line3 = append(line3, txt)
}
gfwids1 := []gowid.IWidget{line1[0], line1[1], line1[2], line1[3], line1[4]}
grid1 := grid.New(gfwids1, 15, 3, 1, gowid.HAlignMiddle{})
gfwids2 := []gowid.IWidget{line2[0], line2[1], line2[2], line2[3], line2[4]}
grid2 := grid.New(gfwids2, 15, 3, 1, gowid.HAlignMiddle{})
gfwids3 := []gowid.IWidget{line3[0], line3[1], line3[2], line3[3], line3[4]}
grid3 := grid.New(gfwids3, 15, 3, 1, gowid.HAlignMiddle{})
grids := make([]gowid.IWidget, 0)
grids = append(grids, grid1)
grids = append(grids, grid2)
grids = append(grids, grid3)
walker := list.NewSimpleListWalker(grids)
lb := list.New(walker)
pw := vpadding.New(lb, gowid.VAlignTop{}, gowid.RenderFlow{})
app, err = gowid.NewApp(gowid.AppArgs{
View: pw,
Palette: &palette,
Log: log.StandardLogger(),
})
app.SimpleMainLoop()
If I start it and press "up" or "down" key - it crashes the following way:
panic: runtime error: integer divide by zero
goroutine 1 [running]:
github.com/gcla/gowid/widgets/grid.GenerateWidgets({0x5f7ce0, 0xc00021a000}, {0x5b06a0, 0x6c9460}, {0x5f5c58, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/grid/grid.go:408 +0x1098
github.com/gcla/gowid/widgets/grid.(*Widget).GenerateWidgets(0xc00021a000, {0x5b06a0, 0x6c9460}, {0x5f5c58, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/grid/grid.go:210 +0x65
github.com/gcla/gowid/widgets/grid.UserInput({0x5f7ce0, 0xc00021a000}, {0x5a9680, 0xc00029f4e0}, {0x5b06a0, 0x6c9460}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/grid/grid.go:326 +0x7ed
github.com/gcla/gowid/widgets/grid.(*Widget).UserInput(0xc00021a000, {0x5a9680, 0xc00029f4e0}, {0x5b06a0, 0x6c9460}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/grid/grid.go:206 +0x98
github.com/gcla/gowid.UserInputIfSelectable({0x5f61f8, 0xc00021a000}, {0x5a9680, 0xc00029f4e0}, {0x5b06a0, 0x6c9460}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/support.go:793 +0xb3
github.com/gcla/gowid/widgets/list.(*Widget).UserInput(0xc0001d7960, {0x5a9680, 0xc00029f4e0}, {0x5b06a0, 0x6c9790}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/list/list.go:717 +0x709
github.com/gcla/gowid.UserInputIfSelectable({0x5f62a0, 0xc0001d7960}, {0x5a9680, 0xc00029f4e0}, {0x5b06a0, 0x6c9790}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/support.go:793 +0xb3
github.com/gcla/gowid/widgets/vpadding.UserInput({0x5f74c0, 0xc000114410}, {0x5a9680, 0xc00029f4e0}, {0x5b4000, 0xc0002a9bd0}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/vpadding/vpadding.go:285 +0x45e
github.com/gcla/gowid/widgets/vpadding.(*Widget).UserInput(0xc000114410, {0x5a9680, 0xc00029f4e0}, {0x5b4000, 0xc0002a9bd0}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/widgets/vpadding/vpadding.go:124 +0x98
github.com/gcla/gowid.UserInputIfSelectable({0x5f6348, 0xc000114410}, {0x5a9680, 0xc00029f4e0}, {0x5b4000, 0xc0002a9bd0}, {0x1, 0x1}, {0x5f8108, 0xc00014a580})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/support.go:793 +0xb3
github.com/gcla/gowid.(*App).handleInputEvent(0xc00014a580, {0x5a9680, 0xc00029f4e0}, {0x5f4500, 0x708e90})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/app.go:665 +0x185
github.com/gcla/gowid.(*App).HandleTCellEvent(0xc00014a580, {0x5a9680, 0xc00029f4e0}, {0x5f4500, 0x708e90})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/app.go:469 +0x945
github.com/gcla/gowid.(*App).handleEvents(0xc00014a580, {0x5f4500, 0x708e90})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/app.go:648 +0x145
github.com/gcla/gowid.(*App).MainLoop(0xc00014a580, {0x5f4500, 0x708e90})
/home/peter/go/pkg/mod/github.com/gcla/gowid@v1.3.0/app.go:629 +0x12d
main.main()
/usr/home/peter/Programming/golang/test1/test1.go:214 +0x2afb
End Process exit status 2
I've just tried the last git version - the same thing (crash at widgets/grid/grid.go:407)
Thanks @Peter2121 , I'll look at this ASAP.
Hi @Peter2121 - I reproduced your crash from your full example above. Sorry it's not fixed yet, but I'll try to get something pushed very soon.
Workaround:
gline := grid.New(line, width, hpad, vpad, gowid.HAlignMiddle{},
grid.Options{
DownKeys: []vim.KeyPress{},
UpKeys: []vim.KeyPress{},
})
So, up/down keys are not processed by grid widget.