nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.66k stars 372 forks source link

Panic on FreeBSD host #235

Open aleksuss opened 3 years ago

aleksuss commented 3 years ago

Hello. I get a panic while trying to run demo:

$ go run _demos/keyboard.go
panic: runtime error: index out of range [15] with length 14
    panic: runtime error: index out of range [14] with length 14

goroutine 1 [running]:
github.com/nsf/termbox-go.Close()
    /home/oleksandr.anyshchenko/termbox-go/api.go:146 +0x4d2
panic(0x4fc5c0, 0xc0000de000)
    /usr/local/go/src/runtime/panic.go:965 +0x1b9
github.com/nsf/termbox-go.SetInputMode(0x5, 0x0)
    /home/oleksandr.anyshchenko/termbox-go/api.go:483 +0x1e5
main.main()
    /home/oleksandr.anyshchenko/termbox-go/_demos/keyboard.go:702 +0x7d
exit status 2

FreeBSD 12.2 Go 1.16.3

dchapes commented 3 years ago

This was fixed in PR #236 by @ncw and merged in 2ff630277754813b198ae96036e28e254d2c72bf by @scrouthtv. There hasn't been a tagged released since then, nor has the broken v1.1.0 been retracted. If you have a module using termbox, I'd suggest adding something like the following to your module's go.mod:

require github.com/nsf/termbox-go v1.1.1-0.20210421210813-2ff630277754

// termbox-go v1.1.0 panics, see https://github.com/nsf/termbox-go/pull/236
exclude github.com/nsf/termbox-go v1.1.0

You can add those lines by hand or safely adjust your existing go.mod (other than the comment) with:

cd $somewhere_within_your_own_termbox_requiring_module
go get github.com/nsf/termbox-go@2ff630277754
go mod edit -exclude=github.com/nsf/termbox-go@v1.1.0

[Edit/Update:] v1.1.1 has been tagged, in your go.mod replace the above @2ff630277754 with @v1.1.1 instead. E.g. 

require github.com/nsf/termbox-go v1.1.1
exclude github.com/nsf/termbox-go v1.1.0

or just run:

go mod edit -exclude=github.com/nsf/termbox-go@v1.1.0
go get github.com/nsf/termbox-go@latest

[/edit]

The exclude line is to prevent any accidental go get -u, go get github.com/nsf/termbox-go@latest, or similar command that anyone runs from within/under your module from going back to the broken v1.1.0 (which Go will tend to do automatically until the next higher compatible version is tagged).

scrouthtv commented 3 years ago

Give me 10 minutes and I'll tag it.. Looks like I messed that up by a lot

scrouthtv commented 3 years ago

Kindly try v1.1.1

@dchapes should I completely delete the v1.1.0 tag?

dchapes commented 3 years ago

Kindly try v1.1.1

Thanks!

@dchapes should I completely delete the v1.1.0 tag?

My understanding is that no, once anyone could have seen a version and it could have gotten into proxy.golang.org then that version should always exist without any changes or "bad-things" will happen (e.g. existing repeatable builds could break if they can't retrieve that version from a proxy).

Instead you could retract that version as per the Go module documentation https://golang.org/ref/mod#go-mod-file-retract (e.g. add a line like retract v1.1.0 // some-reason-for-the-retraction to go.mod).

That would make all the Go commands ignore that version by default (unless explicitly asked, e.g. go list -m -versions -retracted github.com/nsf/termbox-go). Ideally, you'd have made that change to go.mod before you tagged v1.1.1 since retraction lines in go.mod are read from the latest tagged version.

Since you didn't do that (no big deal), I'd probably just edit go.mod to retract v1.1.0 now (just so it's not forgotten about), but leave that change to become visible whenever the next version happens to gets tagged. The alternative would be to make yet another tagged patch release, e.g. something like v1.1.2 with just the go.mod change but that's probably overkill and unneeded tag noise since with the new v1.1.1 anybody not explicitly asking for or depending on v1.1.0 won't get it. [Note: this only makes any difference at all for users of Go1.16+; Go1.15 and lower will ignore the retract directive anyway; another reason for not bothering to make another tag until needed for other changes.] The issue was that until you did the v1.1.1 tag there was a landmine awaiting anyone doing a go get -u or go get github.com/nsf/termbox-go@latest (or even just go get github.com/nsf/termbox-go if they didn't already have a require directive for it) since it would get the broken version; now all those commands will get a working version so the landmine is already defused :). Thanks again.

[Edit: By the way, I just verified that as expected, the command the OP tried, go run _demos/keyboard.go does indeed work with v1.1.1 on FreeBSD so unless something else is broken for the OP then I think this issue can be closed.]

scrouthtv commented 3 years ago

I'd probably just edit go.mod to retract v1.1.0 now

Done - 8f994c

Go1.15 and lower will ignore the retract directive anyway

Ooh that's why I never heard of it before, thanks for teaching me something new :)