Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: slice bounds out of range #166

Open
widon1104 opened this issue Aug 17, 2017 · 9 comments
Open

panic: runtime error: slice bounds out of range #166

widon1104 opened this issue Aug 17, 2017 · 9 comments

Comments

@widon1104
Copy link

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

@soyking
Copy link

soyking commented Apr 4, 2018

Same problem

@iwittkau
Copy link

iwittkau commented Oct 1, 2018

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

@Masterlu1998
Copy link

Masterlu1998 commented Jan 9, 2020

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

@iwittkau
Copy link

iwittkau commented Jan 9, 2020

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.

@Masterlu1998
Copy link

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

@iwittkau
Copy link

iwittkau commented Jan 9, 2020

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

@nsf
Copy link
Owner

nsf commented Jan 9, 2020

moving away from termbox-go

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

@Piknik1990
Copy link

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

@nsf
Copy link
Owner

nsf commented Jun 12, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants