veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.18k stars 219 forks source link

Sudden panic #432

Open Matias-Barrios opened 4 years ago

Matias-Barrios commented 4 years ago
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f4a4f717a10]

runtime stack:
runtime.throw(0x51dacd, 0x2a)
        /usr/local/go/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4cc330, 0xc00004fbe8, 0x100000000000000)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc00004fbb8 sp=0xc00004fb80 pc=0x419f5b
github.com/veandco/go-sdl2/sdl._Cfunc_RenderCopy(0x298b020, 0x43f7010, 0x0, 0x32a000000ce, 0x2400000030, 0x0)
        _cgo_gotypes.go:2065 +0x4d fp=0xc00004fbe8 sp=0xc00004fbb8 pc=0x4b68bd
github.com/veandco/go-sdl2/sdl.(*Renderer).Copy.func2(0x298b020, 0x43f7010, 0x0, 0xc000177880, 0xc000177880)
        /home/matias/go/src/github.com/veandco/go-sdl2/sdl/render.go:785 +0xd9 fp=0xc00004fc38 sp=0xc00004fbe8 pc=0x4b9209
github.com/veandco/go-sdl2/sdl.(*Renderer).Copy(0x298b020, 0x43f7010, 0x0, 0xc000177880, 0x0, 0xc000016570)
        /home/matias/go/src/github.com/veandco/go-sdl2/sdl/render.go:785 +0x52 fp=0xc00004fc70 sp=0xc00004fc38 pc=0x4b87e2
github.com/Matias-Barrios/SDL_Universe/SDL.DrawStuff(0x298b020, 0x43f7010, 0xac, 0x384, 0x28, 0x28)
        /home/matias/go/src/github.com/Matias-Barrios/SDL_Universe/SDL/SDL.go:67 +0xdf fp=0xc00004fcb0 sp=0xc00004fc70 pc=0x4bd95f
github.com/Matias-Barrios/SDL_Universe/board.Draw(0x298b020)
        /home/matias/go/src/github.com/Matias-Barrios/SDL_Universe/board/board.go:63 +0x10a fp=0xc00004fd20 sp=0xc00004fcb0 pc=0x4c075a
main.main()
        /home/matias/go/src/github.com/Matias-Barrios/SDL_Universe/main.go:124 +0x851 fp=0xc00004ff60 sp=0xc00004fd20 pc=0x4c7e01
runtime.main()
        /usr/local/go/src/runtime/proc.go:203 +0x21e fp=0xc00004ffe0 sp=0xc00004ff60 pc=0x4437be
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x46be41
exit status 2

I am having a sudden panic while my game is running. Out of nowhere the app just stops and throws this. It seems to be tied to line 124 in my main.go.

In that specific line I am polling for events. But nothing else.

Any ideas? It happens randomly, sometimes it does not even happen at all.

veeableful commented 4 years ago

Hi @Matias-Barrios, thanks for the issue report! I'll see if I can reproduce it later today.

veeableful commented 4 years ago

Hmm I can't seem to reproduce it. For reference could you tell us the versions of Go, SDL2 and what OS you are running it on? Thanks!

Matias-Barrios commented 4 years ago

Sure this is my OS version :

 $ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

My GO version :

go version go1.13.1 linux/amd64

My SDL2 version :

 $ dpkg -l | grep sdl
ii  libsdl-image1.2:amd64                       1.2.12-5+deb9u1build0.16.04.1                amd64        Image loading library for Simple DirectMedia Layer 1.2, libraries
ii  libsdl-image1.2-dev:amd64                   1.2.12-5+deb9u1build0.16.04.1                amd64        Image loading library for Simple DirectMedia Layer 1.2, development files
ii  libsdl1.2-dev                               1.2.15+dfsg1-3                               amd64        Simple DirectMedia Layer development files
ii  libsdl1.2debian:amd64                       1.2.15+dfsg1-3                               amd64        Simple DirectMedia Layer
ii  libsdl2-2.0-0:amd64                         2.0.4+dfsg1-2ubuntu2.16.04.1                 amd64        Simple DirectMedia Layer
ii  libsdl2-dbg:amd64                           2.0.4+dfsg1-2ubuntu2.16.04.1                 amd64        Simple DirectMedia Layer debug files
ii  libsdl2-dev                                 2.0.4+dfsg1-2ubuntu2.16.04.1                 amd64        Simple DirectMedia Layer development files
ii  libsdl2-doc                                 2.0.4+dfsg1-2ubuntu2.16.04.1                 all          Reference manual for libsdl2
ii  libsdl2-gfx-1.0-0:amd64                     1.0.1+dfsg-3                                 amd64        drawing and graphical effects extension for SDL2
ii  libsdl2-gfx-dbg:amd64                       1.0.1+dfsg-3                                 amd64        debugging symbols for SDL2_gfx
ii  libsdl2-gfx-dev:amd64                       1.0.1+dfsg-3                                 amd64        development files for SDL2_gfx
ii  libsdl2-gfx-doc                             1.0.1+dfsg-3                                 all          documentation files for SDL2_gfx
ii  libsdl2-image-2.0-0:amd64                   2.0.1+dfsg-2+deb9u1build0.16.04.1            amd64        Image loading library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-image-dbg:amd64                     2.0.1+dfsg-2+deb9u1build0.16.04.1            amd64        Image loading library for Simple DirectMedia Layer 2, debugging symbols
ii  libsdl2-image-dev:amd64                     2.0.1+dfsg-2+deb9u1build0.16.04.1            amd64        Image loading library for Simple DirectMedia Layer 2, development files
ii  libsdl2-mixer-2.0-0:amd64                   2.0.1+dfsg1-1                                amd64        Mixer library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-mixer-dbg:amd64                     2.0.1+dfsg1-1                                amd64        Mixer library for Simple DirectMedia Layer 2, debugging
ii  libsdl2-mixer-dev:amd64                     2.0.1+dfsg1-1                                amd64        Mixer library for Simple DirectMedia Layer 2, development files
ii  libsdl2-net-2.0-0:amd64                     2.0.1+dfsg1-2                                amd64        Network library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-net-dbg:amd64                       2.0.1+dfsg1-2                                amd64        Network library for Simple DirectMedia Layer 2, debugging
ii  libsdl2-net-dev:amd64                       2.0.1+dfsg1-2                                amd64        Network library for Simple DirectMedia Layer 2, development files
ii  libsdl2-ttf-2.0-0:amd64                     2.0.14+dfsg1-1                               amd64        TrueType Font library for Simple DirectMedia Layer 2, libraries
ii  libsdl2-ttf-dbg:amd64                       2.0.14+dfsg1-1                               amd64        TrueType Font library for Simple DirectMedia Layer 2, debugging
ii  libsdl2-ttf-dev:amd64                       2.0.14+dfsg1-1                               amd64        TrueType Font library for Simple DirectMedia Layer 2, development files

I am trying to reproduce it as well but it's hard. It happens totally randomly but I am almost sure it happens while either polling or doing a render copy.

Matias-Barrios commented 4 years ago

ok I have pinpointed the issue again. For instance :+1:

       /usr/local/go/src/runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4cc140, 0xc00004fc58, 0x10000c000000180)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc00004fc28 sp=0xc00004fbf0 pc=0x419f5b
github.com/veandco/go-sdl2/sdl._Cfunc_RenderCopy(0x25557f0, 0x3ffe200, 0x0, 0x0, 0x384000004b0, 0xc000000000)
        _cgo_gotypes.go:2065 +0x4d fp=0xc00004fc58 sp=0xc00004fc28 pc=0x4b68bd
github.com/veandco/go-sdl2/sdl.(*Renderer).Copy.func2(0x25557f0, 0x3ffe200, 0x0, 0xc0003cebb0, 0xc0003cebb0)
        /home/matias/go/src/github.com/veandco/go-sdl2/sdl/render.go:785 +0xd9 fp=0xc00004fca8 sp=0xc00004fc58 pc=0x4b9209
github.com/veandco/go-sdl2/sdl.(*Renderer).Copy(0x25557f0, 0x3ffe200, 0x0, 0xc0003cebb0, 0x7e2b4679, 0xa008a4e6c635f98a)
        /home/matias/go/src/github.com/veandco/go-sdl2/sdl/render.go:785 +0x52 fp=0xc00004fce0 sp=0xc00004fca8 pc=0x4b87e2
github.com/Matias-Barrios/SDL_Universe/SDL.DrawStuff(0x25557f0, 0x3ffe200, 0x0, 0x0, 0x3e8, 0x3e8)
        /home/matias/go/src/github.com/Matias-Barrios/SDL_Universe/SDL/SDL.go:67 +0xdf fp=0xc00004fd20 sp=0xc00004fce0 pc=0x4bd95f
main.main()
        /home/matias/go/src/github.com/Matias-Barrios/SDL_Universe/main.go:108 +0x7c8 fp=0xc00004ff60 sp=0xc00004fd20 pc=0x4c7b88
runtime.main()
        /usr/local/go/src/runtime/proc.go:203 +0x21e fp=0xc00004ffe0 sp=0xc00004ff60 pc=0x4437be
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc00004ffe8 sp=0xc00004ffe0 pc=0x46be41
exit status 2

Every time it always points to a DrawStuff function. And my DrawStuff function is only a wrapper on top of render.Copy.

One more hint to something being wrong is that the audio is messed up after a while of playing once again. It seems that mashing buttons seems to help to reproduce the issue. So one way of reproducing this issue faster is mashing buttons like crazy. It might take a minute or two but it always panics.

You can clone the game to your local and try and you should get the same behavior. Also, what editor are you using? Im using VS Code, but if you think that I can debug this better with something else I can try and help you pinpoint the exact bug.

gen2brain commented 4 years ago

@Matias-Barrios did you try with runtime.LockOSThread()? Just put it at start of your main() as noted in FAQ.

Matias-Barrios commented 4 years ago

@gen2brain I have not. I'll do and test again.

Matias-Barrios commented 4 years ago

Hi @gen2brain . I did as you told and the app crashed with the very same panic in just a few minutes as well :(

veeableful commented 4 years ago

Hi @Matias-Barrios, to confirm, are you running the latest version of go-sdl2? Could you run go get -v -u github.com/veandco/go-sdl2/sdl and rebuild your program by running go build -a? I was under the impression that the sound issues have been fixed in the master branch but perhaps there's other audio issues.

I tried to reproduce the issue under the same environment (albeit in a virtual machine) but was unable to do it. I'll try again using native environment with some spare hardware that I have!

EDIT: Oh and if you happen to use Go modules, could try to temporarily replace your Go version to Go 1.10.x and rebuild with go build -a to check if it still happens?

Matias-Barrios commented 4 years ago

Hi @veeableful. Im sharing this video where I demonstrate the bug. I have updated the packages and the issue still persist. Although there is no audio in the recording, the game in fact lost the audio after reproducing a few times.

https://youtu.be/Qf4T5xKBdR8

Note - I am not using Go modules. But I can downgrade my version of Go if you think is worth it. I also tried building with -a but it got hanged anyway.

veeableful commented 4 years ago

Well! After I installed Ubuntu MATE 16.04.6 (normal Ubuntu doesn't seem to work on my old Samsung Chromebook), I can at least reproduce it somewhat although it crashed at a different place. That gives me something to work with at least! I'll report back if I found something.

veeableful commented 4 years ago

Hi @Matias-Barrios, I haven't pinned down why exactly it segfaults but I noticed that the memory usage goes up quite high overtime (around 300M from 50M) before it crashes. Perhaps reducing the memory leak might help for now while I continue investigating.