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

Negative TableCellID Row #2857

Closed
Aj5y8HBIFf opened this issue Mar 20, 2022 · 2 comments
Closed

Negative TableCellID Row #2857

Aj5y8HBIFf opened this issue Mar 20, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Aj5y8HBIFf
Copy link

Aj5y8HBIFf commented Mar 20, 2022

Describe the bug:

I get a negative TableCellID Row when table is too wide (?).

The bug seems to be due to this line

offY := r.cells.t.offset.Y - float32(int(r.cells.t.offset.Y)%int(r.cells.cellSize.Height+separatorThickness))

r.cells.t.offset.Y is negative for some reason.

Adding the following code fixes the issue:

if r.cells.t.offset.Y < 0 {
	r.cells.t.offset.Y = 0
}
panic: runtime error: index out of range [-3]

goroutine 50 [running]:
main.main.func3({0xc000108270?, 0xc042a01800?}, {0x4470d78?, 0xc000108270?})
        /Users/xxx/Documents/project/cmd/test1/main.go:24 +0xa5
fyne.io/fyne/v2/widget.(*tableCellsRenderer).Refresh(0xc0000b4240)
        /Users/xxx/Documents/project/vendor/fyne.io/fyne/v2/widget/table.go:673 +0x691
fyne.io/fyne/v2/widget.(*BaseWidget).Refresh(0xc0000ba000?)
        /Users/xxx/Documents/project/vendor/fyne.io/fyne/v2/widget/widget.go:138 +0x2e
fyne.io/fyne/v2/widget.(*Table).finishScroll(0xc0003c0820)
        /Users/xxx/Documents/project/vendor/fyne.io/fyne/v2/widget/table.go:289 +0x4e
fyne.io/fyne/v2/widget.(*Table).ScrollToBottom(0xc0003c0820)
        /Users/xxx/Documents/project/vendor/fyne.io/fyne/v2/widget/table.go:215 +0x9f
main.main.func4()
        /Users/xxx/Documents/project/cmd/test1/main.go:33 +0x149
created by main.main
        /Users/xxx/Documents/project/cmd/test1/main.go:30 +0x319

Process finished with the exit code 2

To Reproduce:

Steps to reproduce the behaviour:

  1. Run the below script

Example code:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
	"strconv"
	"time"
)

func main() {
	a := app.New()
	w := a.NewWindow("Some title")

	tableData := make([][]string, 0)
	table := widget.NewTable(func() (int, int) { return len(tableData), 3 },
		func() fyne.CanvasObject {
			item := widget.NewLabel("template")
			return item
		},
		func(i widget.TableCellID, o fyne.CanvasObject) {
			o.(*widget.Label).SetText(tableData[i.Row][i.Col])
		})
	table.SetColumnWidth(0, 40)
	table.SetColumnWidth(1, 80)
	table.SetColumnWidth(2, 80)

	go func() {
		time.Sleep(3 * time.Second)
		tableData = append(tableData, []string{strconv.Itoa(len(tableData) + 1), "test1", "test2"})
		table.ScrollToBottom()
	}()

	c := container.New(layout.NewMaxLayout(), table)

	w.SetContent(c)
	w.Resize(fyne.NewSize(300, 200))
	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: MacOS
  • Version: 12.1 Monterey
  • Go version: 1.18
  • Fyne version: 2.1.4
@Aj5y8HBIFf Aj5y8HBIFf added the unverified A bug that has been reported but not verified label Mar 20, 2022
@lisx123
Copy link

lisx123 commented Mar 30, 2022

cool bro,thanks

@andydotxyz
Copy link
Member

Fixed on develop and release branch for 2.3.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants