Fergulator icon indicating copy to clipboard operation
Fergulator copied to clipboard

Race condition in startup causing panic

Open xaviershay opened this issue 10 years ago • 3 comments

This only happens sometimes. Have noticed on many different ROMs, so I don't think it is ROM specific.

On OSX Yosemite.

> ./Fergulator test_roms/nestest.nes
2015/02/08 12:15:10 nestest .nestest.state
-----------------
ROM:
  PRG-ROM banks: 1 (1 real)
  CHR-ROM banks: 2 (1 real)
  Mirroring: Horizontal
  Mapper: 0x0 -> NROM
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x3b0 pc=0x7fff92b59c30]

runtime stack:
runtime.gothrow(0x43986f0, 0x2a)
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/panic.go:503 +0x8e
runtime.sigpanic()
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/sigpanic_unix.go:14 +0x5e

goroutine 1 [syscall, locked to thread]:
runtime.cgocall_errno(0x40042a0, 0xc2080e7cf8, 0xc200000000)
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/cgocall.go:130 +0xf5 fp=0xc2080e7cd8 sp=0xc2080e7cb0
github.com/go-gl/gl._Cfunc_glewInit(0x0)
    github.com/go-gl/gl/_obj/_cgo_gotypes.go:4399 +0x4b fp=0xc2080e7cf8 sp=0xc2080e7cd8
github.com/go-gl/gl.Init(0xc20800c700)
    /Users/xavier/Code/go/src/github.com/go-gl/gl/gl.go:1232 +0x28 fp=0xc2080e7d08 sp=0xc2080e7cf8
main.(*Video).initGL(0x45c6660)
    /Users/xavier/Code/go/src/github.com/scottferg/Fergulator/video.go:86 +0x27 fp=0xc2080e7da8 sp=0xc2080e7d08
main.(*Video).Init(0x45c6660, 0xc20809b3e0, 0x7fff5fbff79f, 0x7)
    /Users/xavier/Code/go/src/github.com/scottferg/Fergulator/video.go:76 +0x392 fp=0xc2080e7e40 sp=0xc2080e7da8
main.main()
    /Users/xavier/Code/go/src/github.com/scottferg/Fergulator/main.go:77 +0xaa1 fp=0xc2080e7f98 sp=0xc2080e7e40
runtime.main()
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/proc.go:63 +0xf3 fp=0xc2080e7fe0 sp=0xc2080e7f98
runtime.goexit()
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc2080e7fe8 sp=0xc2080e7fe0

goroutine 5 [chan send]:
github.com/scottferg/Go-SDL/sdl.pollEvents()
    /Users/xavier/Code/go/src/github.com/scottferg/Go-SDL/sdl/event.go:37 +0x1dc
created by github.com/scottferg/Go-SDL/sdl.init·1
    /Users/xavier/Code/go/src/github.com/scottferg/Go-SDL/sdl/event.go:64 +0x25

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/1.4.1/libexec/src/runtime/asm_amd64.s:2232 +0x1

xaviershay avatar Feb 08 '15 20:02 xaviershay

Looks similar to latest updates on https://github.com/tedsta/gosfml/issues/2

xaviershay avatar Feb 08 '15 21:02 xaviershay

It's definitely not ROM specific and it's plagued me for ages. Thanks for the formal bug, I need a kick in the butt to fix this since it's pretty bad these days.

scottferg avatar Feb 09 '15 17:02 scottferg

Things I have learned. Much of this is likely obvious.

It's a segfault in C-code

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x3b0 pc=0x7fff92b59c30]

From https://groups.google.com/forum/#!topic/golang-nuts/65pdWIYga4E "code 0x0b is 11, which is SIGSEGV."

glewInit segfaults all the time

https://www.google.com/webhp?#q=glewinit%20segfault D:

Reproducing

Comment out everything after videoOut.Init(videoTick, nes.GameName) in main.go, which means it will exit as soon as it has inited, then: `while ./Fergulator smb.nes; do; done. That reliably produces a crash within a few runs.

Adding a one second sleep before the Init code, I still get crashes.

Commenting out everything except video init avoids the crash. EDIT: that's because it's equivalent to the workaround...

Workaround

PR incoming.

xaviershay avatar Feb 10 '15 02:02 xaviershay