Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crashes - "integer divide by zero" #40

Open
Peter2121 opened this issue Feb 11, 2022 · 4 comments
Open

Application crashes - "integer divide by zero" #40

Peter2121 opened this issue Feb 11, 2022 · 4 comments

Comments

@Peter2121
Copy link

Peter2121 commented Feb 11, 2022

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

@Peter2121
Copy link
Author

I've just tried the last git version - the same thing (crash at widgets/grid/grid.go:407)

@gcla
Copy link
Owner

gcla commented Feb 11, 2022

Thanks @Peter2121 , I'll look at this ASAP.

@gcla
Copy link
Owner

gcla commented Feb 14, 2022

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.

@Peter2121
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants