nsf / termbox-go

Pure Go termbox implementation

Home Page:http://godoc.org/github.com/nsf/termbox-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic: runtime error: slice bounds out of range

widon1104 opened this issue · comments

panic: runtime error: slice bounds out of range --------------------+

goroutine 15 [running]:
github.com/nsf/termbox-go.PollEvent(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/widon/golang/src/github.com/nsf/termbox-go/api.go:330 +0x7ca
golang2048_game/g2048.(*G2048).mrgeAndReturnKey.func1(0xc42001c4e0)
/home/widon/golang/src/golang2048_game/g2048/2048.go:252 +0x34
created by golang2048_game/g2048.(*G2048).mrgeAndReturnKey
/home/widon/golang/src/golang2048_game/g2048/2048.go:254 +0x91

api.go: 330 copy(inbuf, inbuf[event.N:])
I print the len(inbuf) and event.N is 0, 3

Same problem

I sometimes run into this issue using gocui

panic: runtime error: slice bounds out of range

goroutine 8 [running]:
github.com/nsf/termbox-go.PollEvent(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/iwittkau/go/src/github.com/nsf/termbox-go/api.go:330 +0x65c
github.com/jroimartin/gocui.(*Gui).MainLoop.func1(0xc4201ee000) 
        /Users/iwittkau/go/src/github.com/jroimartin/gocui/gui.go:354 +0x30
created by github.com/jroimartin/gocui.(*Gui).MainLoop
	/Users/iwittkau/go/src/github.com/jroimartin/gocui/gui.go:352 +0x6e

Did anyone solve this problem? I got the same problem when i using termui

I still see this from time to time, unfortunately it is not very easy to reproduce. It happens when I navigate through a list with the keyboard arrow keys.

yeah, same with me, but it seems to be not happened in a simple list witch is termui official example. It is weird, very weird...

https://github.com/gizak/termui/blob/master/_examples/list.go

I'm looking into moving away from termbox-go anyway, since it's not actively maintained anymore.

commented

moving away from termbox-go

That's a good idea, consider using https://github.com/gdamore/tcell

I don't know if my situation is the same or something else, but nevertheless I will leave my information here

I came across this error when I was doing logic with pressing Space or Enter and wanted to do tricky logic with binary flags and using this flag in various places of the program.

As a result, it worked, but the Panic occurred as suddenly as possible and not at the time.

Later I reduced the logic using flags and the application began to work stably. I think it's a reaction to the termbox.Key* must be strictly immediately after pressing, and if this trigger is worked out later, there is a risk of this error.

My fix: Piknik1990/countdowndsm@9d558e1

commented

Not sure about other cases, but @Piknik1990's case might be the race condition. I see you run multiple goroutines here: https://github.com/Piknik1990/countdowndsm/blob/9d558e149463fbf3c14f8e99056ac3931ac07bc5/main.go#L108-L136 and all do "termbox.PollEvent()". Termbox is not really a thread safe library. You can in theory use event polling and drawing code in separate threads. But it doesn't mean you can poll events from multiple threads.

I'd guess other panics like that might be of similar origin. Worth trying the race detector (although it might be tricky to use it with a terminal ui program, figure out how to redirect its output, etc).