[PR #562] [CLOSED] Fix crashing in textview.go #984

Closed
opened 2026-03-04 01:08:52 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rivo/tview/pull/562
Author: @inmylo
Created: 2/8/2021
Status: Closed

Base: masterHead: patch-1


📝 Commits (1)

  • e0f5e0b Fix crashing in textview.go

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 textview.go (+1 -1)

📄 Description

My application has a textView, which is being updated very often, for example each millisecond. It sometimes crashes when I try to close a modal window with app.SetRoot(pages, true). I've figured out, that this PR's t.buffer is sometimes empty, so I tried to add an additional check and it seems to help. You can choose a more efficient way if such exists. Some time ago I got a similar error at line 826 str := t.buffer[line.Line][line.Pos:line.NextPos] - maybe it should be fixed too.

Panic's error:

panic: runtime error: index out of range [1] with length 0 [recovered]
	panic: runtime error: index out of range [1] with length 0

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1(0xc00015e000)
	/path/src/github.com/rivo/tview/application.go:243 +0x87
panic(0x5916e0, 0xc0001b40c0)
	/path/src/runtime/panic.go:969 +0x1b9
github.com/rivo/tview.(*TextView).Draw(0xc000152300, 0x5da440, 0xc0000d6600)
	/path/src/github.com/rivo/tview/textview.go:947 +0xded
github.com/rivo/tview.(*Grid).Draw(0xc000162090, 0x5da440, 0xc0000d6600)
	/path/src/github.com/rivo/tview/grid.go:626 +0x12cf
github.com/rivo/tview.(*Pages).Draw(0xc00009ad80, 0x5da440, 0xc0000d6600)
	/path/src/github.com/rivo/tview/pages.go:277 +0xb9
github.com/rivo/tview.(*Application).draw(0xc00015e000, 0x0)
	/path/src/github.com/rivo/tview/application.go:595 +0xd9
github.com/rivo/tview.(*Application).Run(0xc00015e000, 0x0, 0x0)
	/path/src/github.com/rivo/tview/application.go:343 +0x625
main.main()
	/path/src/github.com/user/myapp/main.go:43 +0x88
exit status 2

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rivo/tview/pull/562 **Author:** [@inmylo](https://github.com/inmylo) **Created:** 2/8/2021 **Status:** ❌ Closed **Base:** `master` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`e0f5e0b`](https://github.com/rivo/tview/commit/e0f5e0b1b8ffaa11557fab33566b2cdc858fd3c6) Fix crashing in textview.go ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `textview.go` (+1 -1) </details> ### 📄 Description My application has a **textView**, which is being updated very often, for example each millisecond. It sometimes crashes when I try to close a modal window with `app.SetRoot(pages, true)`. I've figured out, that this PR's `t.buffer` is sometimes empty, so I tried to add an additional check and it seems to help. You can choose a more efficient way if such exists. Some time ago I got a similar error at line 826 `str := t.buffer[line.Line][line.Pos:line.NextPos]` - maybe it should be fixed too. Panic's error: ``` panic: runtime error: index out of range [1] with length 0 [recovered] panic: runtime error: index out of range [1] with length 0 goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1(0xc00015e000) /path/src/github.com/rivo/tview/application.go:243 +0x87 panic(0x5916e0, 0xc0001b40c0) /path/src/runtime/panic.go:969 +0x1b9 github.com/rivo/tview.(*TextView).Draw(0xc000152300, 0x5da440, 0xc0000d6600) /path/src/github.com/rivo/tview/textview.go:947 +0xded github.com/rivo/tview.(*Grid).Draw(0xc000162090, 0x5da440, 0xc0000d6600) /path/src/github.com/rivo/tview/grid.go:626 +0x12cf github.com/rivo/tview.(*Pages).Draw(0xc00009ad80, 0x5da440, 0xc0000d6600) /path/src/github.com/rivo/tview/pages.go:277 +0xb9 github.com/rivo/tview.(*Application).draw(0xc00015e000, 0x0) /path/src/github.com/rivo/tview/application.go:595 +0xd9 github.com/rivo/tview.(*Application).Run(0xc00015e000, 0x0, 0x0) /path/src/github.com/rivo/tview/application.go:343 +0x625 main.main() /path/src/github.com/user/myapp/main.go:43 +0x88 exit status 2 ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 01:08:52 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#984
No description provided.