[GH-ISSUE #67] presentation demo, crash on table #47

Closed
opened 2026-03-04 01:01:25 +03:00 by kerem · 4 comments
Owner

Originally created by @glycerine on GitHub (Mar 9, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/67

tview looks fantastic. Thank you immensely for making this.

I was playing with the demos/presentation app. On the (8) table tab, inside (n) navigation,
if I use the down arrow key to scroll all the way to the bottom of the table, and then use the right arrow key to scroll all the way to the right, I seem to make it reliably crash.

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1(0xc42012e2a0)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:85 +0x82
panic(0x118ff40, 0x1299f40)
        /usr/local/go/src/runtime/panic.go:505 +0x229
github.com/rivo/tview.(*Table).Draw(0xc4201d59a0, 0x11e5100, 0xc4200969c0)
        /Users/jaten/go/src/github.com/rivo/tview/table.go:626 +0x239d
github.com/rivo/tview.(*Flex).Draw(0xc4202bc3f0, 0x11e5100, 0xc4200969c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Flex).Draw(0xc4202bc3c0, 0x11e5100, 0xc4200969c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Pages).Draw(0xc42008c810, 0x11e5100, 0xc4200969c0)
        /Users/jaten/go/src/github.com/rivo/tview/pages.go:242 +0xd8
github.com/rivo/tview.(*Flex).Draw(0xc4202bd290, 0x11e5100, 0xc4200969c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Application).Draw(0xc42012e2a0, 0xc4204fb5c0)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:190 +0xcf
github.com/rivo/tview.(*Application).Run(0xc42012e2a0, 0x0, 0x0)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:133 +0x2fd
main.main()
        /Users/jaten/go/src/github.com/rivo/tview/demos/presentation/main.go:92 +0xa72
exit status 2
^[[Cjaten@Jasons-MacBook-Pro ~/go/src/github.com/rivo/tview/demos/presentation (master) $
Originally created by @glycerine on GitHub (Mar 9, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/67 `tview` looks fantastic. Thank you immensely for making this. I was playing with the demos/presentation app. On the (8) table tab, inside (n) navigation, if I use the down arrow key to scroll all the way to the bottom of the table, and then use the right arrow key to scroll all the way to the right, I seem to make it reliably crash. ~~~ goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1(0xc42012e2a0) /Users/jaten/go/src/github.com/rivo/tview/application.go:85 +0x82 panic(0x118ff40, 0x1299f40) /usr/local/go/src/runtime/panic.go:505 +0x229 github.com/rivo/tview.(*Table).Draw(0xc4201d59a0, 0x11e5100, 0xc4200969c0) /Users/jaten/go/src/github.com/rivo/tview/table.go:626 +0x239d github.com/rivo/tview.(*Flex).Draw(0xc4202bc3f0, 0x11e5100, 0xc4200969c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Flex).Draw(0xc4202bc3c0, 0x11e5100, 0xc4200969c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Pages).Draw(0xc42008c810, 0x11e5100, 0xc4200969c0) /Users/jaten/go/src/github.com/rivo/tview/pages.go:242 +0xd8 github.com/rivo/tview.(*Flex).Draw(0xc4202bd290, 0x11e5100, 0xc4200969c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Application).Draw(0xc42012e2a0, 0xc4204fb5c0) /Users/jaten/go/src/github.com/rivo/tview/application.go:190 +0xcf github.com/rivo/tview.(*Application).Run(0xc42012e2a0, 0x0, 0x0) /Users/jaten/go/src/github.com/rivo/tview/application.go:133 +0x2fd main.main() /Users/jaten/go/src/github.com/rivo/tview/demos/presentation/main.go:92 +0xa72 exit status 2 ^[[Cjaten@Jasons-MacBook-Pro ~/go/src/github.com/rivo/tview/demos/presentation (master) $ ~~~
kerem closed this issue 2026-03-04 01:01:25 +03:00
Author
Owner

@glycerine commented on GitHub (Mar 9, 2018):

Seems to depend upon having the screen at a particular size though. If I expand the screen after the crash (with zoomed in screen, not alot of text), I can see that it is an index out of range error.


  (b) Basic table                   func main() {
  (s) Table with separator              table := tview.NewTable().
  (o) Table with borders                    SetFixed(1, 1).
  (r) Selectable rows                       SetSelectable(false, true)
  (c) Selectable columns                for row := 0; row < 40; row++ {
  (l) Selectable cells                      for column := 0; column < 7; column++ {
  (n) Navigate                                  color := tcell.ColorWhite
  (x) Next slide                                if row == 0 {
                                                    color = tcell.ColorYellow
╔═════════════Table══════════════╗              } else if column == 0 {
║OrderDate Units UnitCost Total  ║                  color = tcell.ColorDarkCyan
║2/26/2017    27    19.99 539.73 ║              }
║3/15/2017    56     2.99 167.44 ║              align := tview.AlignLeft
║ 4/1/2017    60     4.99 299.40 ║              if row == 0 {
║4/18/2017    75     1.99 149.25 ║                  align = tview.AlignCenter
║ 5/5/2017    90     4.99 449.10 ║              } else if column == 0 || column >= 4 {
║5/22/2017    32     1.99  63.68 ║                  align = tview.AlignRight
║ 6/8/2017    60     8.99 539.40 ║              }
║6/25/2017    90     4.99 449.10 ║              table.SetCell(row,
║7/12/2017    29     1.99  57.71 ║                  column,
╚════════════════════════════════╝
1 Start  2 Introduction  3 Hello, world  4 Input  5 Forms  6 Text 1  7 Text 2  8 Table  9
panic: runtime error: index out of range [recovered]
        panic: runtime error: index out of range

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1(0xc4201122a0)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:85 +0x82
panic(0x118ff40, 0x1299f40)
        /usr/local/go/src/runtime/panic.go:505 +0x229
github.com/rivo/tview.(*Table).Draw(0xc4201b99a0, 0x11e5100, 0xc42008a9c0)
        /Users/jaten/go/src/github.com/rivo/tview/table.go:626 +0x239d
github.com/rivo/tview.(*Flex).Draw(0xc4202a03f0, 0x11e5100, 0xc42008a9c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Flex).Draw(0xc4202a03c0, 0x11e5100, 0xc42008a9c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Pages).Draw(0xc420086810, 0x11e5100, 0xc42008a9c0)
        /Users/jaten/go/src/github.com/rivo/tview/pages.go:242 +0xd8
github.com/rivo/tview.(*Flex).Draw(0xc4202a1290, 0x11e5100, 0xc42008a9c0)
        /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464
github.com/rivo/tview.(*Application).Draw(0xc4201122a0, 0xc420244f30)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:190 +0xcf
github.com/rivo/tview.(*Application).Run(0xc4201122a0, 0x0, 0x0)
        /Users/jaten/go/src/github.com/rivo/tview/application.go:133 +0x2fd
main.main()
        /Users/jaten/go/src/github.com/rivo/tview/demos/presentation/main.go:92 +0xa72
exit status 2
jaten@Jasons-MacBook-Pro ~/go/src/github.com/rivo/tview/demos/presentation (master) $
<!-- gh-comment-id:371950325 --> @glycerine commented on GitHub (Mar 9, 2018): Seems to depend upon having the screen at a particular size though. If I expand the screen after the crash (with zoomed in screen, not alot of text), I can see that it is an index out of range error. ~~~ (b) Basic table func main() { (s) Table with separator table := tview.NewTable(). (o) Table with borders SetFixed(1, 1). (r) Selectable rows SetSelectable(false, true) (c) Selectable columns for row := 0; row < 40; row++ { (l) Selectable cells for column := 0; column < 7; column++ { (n) Navigate color := tcell.ColorWhite (x) Next slide if row == 0 { color = tcell.ColorYellow ╔═════════════Table══════════════╗ } else if column == 0 { ║OrderDate Units UnitCost Total ║ color = tcell.ColorDarkCyan ║2/26/2017 27 19.99 539.73 ║ } ║3/15/2017 56 2.99 167.44 ║ align := tview.AlignLeft ║ 4/1/2017 60 4.99 299.40 ║ if row == 0 { ║4/18/2017 75 1.99 149.25 ║ align = tview.AlignCenter ║ 5/5/2017 90 4.99 449.10 ║ } else if column == 0 || column >= 4 { ║5/22/2017 32 1.99 63.68 ║ align = tview.AlignRight ║ 6/8/2017 60 8.99 539.40 ║ } ║6/25/2017 90 4.99 449.10 ║ table.SetCell(row, ║7/12/2017 29 1.99 57.71 ║ column, ╚════════════════════════════════╝ 1 Start 2 Introduction 3 Hello, world 4 Input 5 Forms 6 Text 1 7 Text 2 8 Table 9 panic: runtime error: index out of range [recovered] panic: runtime error: index out of range goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1(0xc4201122a0) /Users/jaten/go/src/github.com/rivo/tview/application.go:85 +0x82 panic(0x118ff40, 0x1299f40) /usr/local/go/src/runtime/panic.go:505 +0x229 github.com/rivo/tview.(*Table).Draw(0xc4201b99a0, 0x11e5100, 0xc42008a9c0) /Users/jaten/go/src/github.com/rivo/tview/table.go:626 +0x239d github.com/rivo/tview.(*Flex).Draw(0xc4202a03f0, 0x11e5100, 0xc42008a9c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Flex).Draw(0xc4202a03c0, 0x11e5100, 0xc42008a9c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Pages).Draw(0xc420086810, 0x11e5100, 0xc42008a9c0) /Users/jaten/go/src/github.com/rivo/tview/pages.go:242 +0xd8 github.com/rivo/tview.(*Flex).Draw(0xc4202a1290, 0x11e5100, 0xc42008a9c0) /Users/jaten/go/src/github.com/rivo/tview/flex.go:153 +0x464 github.com/rivo/tview.(*Application).Draw(0xc4201122a0, 0xc420244f30) /Users/jaten/go/src/github.com/rivo/tview/application.go:190 +0xcf github.com/rivo/tview.(*Application).Run(0xc4201122a0, 0x0, 0x0) /Users/jaten/go/src/github.com/rivo/tview/application.go:133 +0x2fd main.main() /Users/jaten/go/src/github.com/rivo/tview/demos/presentation/main.go:92 +0xa72 exit status 2 jaten@Jasons-MacBook-Pro ~/go/src/github.com/rivo/tview/demos/presentation (master) $ ~~~
Author
Owner

@glycerine commented on GitHub (Mar 10, 2018):

at https://github.com/rivo/tview/blob/master/table.go#L626

when I log the index and widths, the crash happens when:

widths ='[]int{10, 9, 9}', len(widths)=3, index=3

the relevant portion of table.go


    // If we have space left, distribute it.
    if tableWidth < width {
        toDistribute := width - tableWidth
        for index, expansion := range expansions {
            if expansionTotal <= 0 {
                break
            }
            expWidth := toDistribute * expansion / expansionTotal
            fmt.Fprintf(mylog, "widths ='%#v', len(widths)=%v, index=%v\n", widths, len(widths), index)
            widths[index] += expWidth        //<<<<<<<<<<< original line 626, where the crash is
            tableWidth += expWidth
            toDistribute -= expWidth
            expansionTotal -= expansion
        }
    }

index is indeed out of bounds.

<!-- gh-comment-id:371983462 --> @glycerine commented on GitHub (Mar 10, 2018): at https://github.com/rivo/tview/blob/master/table.go#L626 when I log the index and widths, the crash happens when: `widths ='[]int{10, 9, 9}', len(widths)=3, index=3` the relevant portion of table.go ~~~ // If we have space left, distribute it. if tableWidth < width { toDistribute := width - tableWidth for index, expansion := range expansions { if expansionTotal <= 0 { break } expWidth := toDistribute * expansion / expansionTotal fmt.Fprintf(mylog, "widths ='%#v', len(widths)=%v, index=%v\n", widths, len(widths), index) widths[index] += expWidth //<<<<<<<<<<< original line 626, where the crash is tableWidth += expWidth toDistribute -= expWidth expansionTotal -= expansion } } ~~~ `index` is indeed out of bounds.
Author
Owner

@glycerine commented on GitHub (Mar 10, 2018):

at slightly bigger zoom (fewer rows/columns on the screen), I print the expansions slice to see it after a crash:

widths ='[]int{10, 10}', len(widths)=2, index=2, expansions='[]int{0, 1, 1, 1, 0, 0, 0}'

so index might go up to 6 here, but widths is only length 2.

<!-- gh-comment-id:371983941 --> @glycerine commented on GitHub (Mar 10, 2018): at slightly bigger zoom (fewer rows/columns on the screen), I print the expansions slice to see it after a crash: ~~~ widths ='[]int{10, 10}', len(widths)=2, index=2, expansions='[]int{0, 1, 1, 1, 0, 0, 0}' ~~~ so `index` might go up to 6 here, but widths is only length 2.
Author
Owner

@rivo commented on GitHub (Mar 10, 2018):

Thank you for pointing this out. I just committed a fix to this.

I'm closing your pull request because the solution was not to check the bounds of the widths variable but to keep the expansions slice the same length as widths. They need to be in sync but I had forgotten to remove an element when removing an element from widths. (Your commit would have led to other problems down the line.)

But thanks again for taking the time to look into this.

<!-- gh-comment-id:372024867 --> @rivo commented on GitHub (Mar 10, 2018): Thank you for pointing this out. I just committed a fix to this. I'm closing your pull request because the solution was not to check the bounds of the `widths` variable but to keep the `expansions` slice the same length as `widths`. They need to be in sync but I had forgotten to remove an element when removing an element from `widths`. (Your commit would have led to other problems down the line.) But thanks again for taking the time to look into this.
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#47
No description provided.