Skip to content

TreeView panics with 'index out of range' error #262

@urandom

Description

@urandom

For some reason, during TreeView's process, the code tries to get a node outside the index. The problem is that the tree does not have any nodes yet.

The stack trace:

github.com/rivo/tview.(*Application).Run.func1(0xc000268f00)
	/home/urandom/.go/src/github.com/rivo/tview/application.go:149 +0x82
panic(0x114ba80, 0x1e28b80)
	/usr/lib/go/src/runtime/panic.go:522 +0x1b5
github.com/rivo/tview.(*TreeView).process(0xc000269000)
	/home/urandom/.go/src/github.com/rivo/tview/treeview.go:501 +0x432
github.com/rivo/tview.(*TreeView).Draw(0xc000269000, 0x146c160, 0xc0002416c0)
	/home/urandom/.go/src/github.com/rivo/tview/treeview.go:543 +0x931
github.com/rivo/tview.(*Flex).Draw(0xc0002cf0b0, 0x146c160, 0xc0002416c0)
	/home/urandom/.go/src/github.com/rivo/tview/flex.go:169 +0x290
github.com/rivo/tview.(*Flex).Draw(0xc0002cf050, 0x146c160, 0xc0002416c0)
	/home/urandom/.go/src/github.com/rivo/tview/flex.go:169 +0x290
github.com/rivo/tview.(*Pages).Draw(0xc0002cefc0, 0x146c160, 0xc0002416c0)
	/home/urandom/.go/src/github.com/rivo/tview/pages.go:246 +0xf1
github.com/rivo/tview.(*Application).draw(0xc000268f00, 0x0)
	/home/urandom/.go/src/github.com/rivo/tview/application.go:363 +0xd8
github.com/rivo/tview.(*Application).QueueUpdateDraw.func1()
	/home/urandom/.go/src/github.com/rivo/tview/application.go:494 +0x3d
github.com/rivo/tview.(*Application).Run(0xc000268f00, 0x0, 0x0)
	/home/urandom/.go/src/github.com/rivo/tview/application.go:253 +0x4dd

The simplest fix might be to return early from the process method if there are no nodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions