Skip to content

ListWidget with data index out of binds when modified binded data  #5227

@deoxyimran

Description

@deoxyimran

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When i modify the binded data like shrinking or growing the backing slice and call reload on the data afterwards, I get this internal error message from fyne:

2024/10/27 18:57:28 Fyne error:  Error getting current data value
2024/10/27 18:57:28   Cause: index out of bounds
2024/10/27 18:57:28   At: /home/darkc0der/go/pkg/mod/fyne.io/fyne/[email protected]/widget/label.go:165

The app doesnt crash or work abnormally afterwards, it runs just fine like before. But the error message reappears everytime I shrink the slice further due to item deletion and reload the bind...hinting that something was accessed out of binds--old indices still being kept around, maybe?

How to reproduce

Already explained in the bug description...

Screenshots

No response

Example code

dataBind = binding.BindStringList( & titles)
notes := widget.NewListWithData(
    dataBind,
    func() fyne.CanvasObject {
        return widget.NewLabel("")
    },
    func(di binding.DataItem, co fyne.CanvasObject) {
        co.( * widget.Label).Bind(di.(binding.String))
    },
)

trash := newTrashButton(trashIcoRes)
trash.onTapped = func() {
    if len(tempTitles) != 0 {
        notes.Unselect(currentItemID)
        textPane.Hide()
        tempTitles = slices.Delete(tempTitles, currentItemID, currentItemID + 1)
        tempEditorTexts = slices.Delete(tempEditorTexts, currentItemID, currentItemID + 1)
        search(titleEntry.Text)
    } else {
        notes.Unselect(currentItemID)
        textPane.Hide()
        titles = slices.Delete(titles, currentItemID, currentItemID + 1)
        editorTexts = slices.Delete(editorTexts, currentItemID, currentItemID + 1)
        dataBind.Reload()
    }
}

Fyne version

2.5.2

Go compiler version

1.21.6

Operating system and version

linux/amd64

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions