veandco / go-sdl2

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

Crash on running Go-SDL2 app through Rosetta #540

Open SolarLune opened 2 years ago

SolarLune commented 2 years ago

Hello!

Just wanted to see if anybody knew anything about this particular issue - I'm the creator of a productivity and organization app known as MasterPlan. It's written with go-sdl2, and has been working pretty well. Normally, I build on GitHub Actions through Mac OS 10.15 - you can see the setup script for the action here.

However, some M1 Mac users have reported that the app crashes on initial startup for them - looks like it's due to sdl_ttf; this is the result that a user got on attempting to run the program through the terminal.

MasterPlan.app/Contents/MacOS/MasterPlan ; exit;
SIGILL: illegal instruction
PC=0x46d373e m=0 sigcode=1
signal arrived during cgo execution
instruction bytes: 0xc5 0xf8 0x57 0xc0 0xc5 0xf8 0x11 0x47 0x28 0xc5 0xf8 0x11 0x47 0x18 0xc5 0xf8

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4491750, 0xc00029f920)
    /Users/runner/hostedtoolcache/go/1.17.11/x64/src/runtime/cgocall.go:156 +0x5c fp=0xc00029f8f8 sp=0xc00029f8c0 pc=0x40136fc
github.com/veandco/go-sdl2/ttf._Cfunc_TTF_Init()
    _cgo_gotypes.go:461 +0x48 fp=0xc00029f920 sp=0xc00029f8f8 pc=0x4171a08
github.com/veandco/go-sdl2/ttf.Init()
    /Users/runner/go/pkg/mod/github.com/veandco/go-sdl2@v0.4.21/ttf/sdl_ttf.go:56 +0x19 fp=0xc00029f938 sp=0xc00029f920 pc=0x4171f79
main.main()
    /Users/runner/work/masterplan/masterplan/main.go:186 +0x8ee fp=0xc00029ff80 sp=0xc00029f938 pc=0x443c2ae
runtime.main()
    /Users/runner/hostedtoolcache/go/1.17.11/x64/src/runtime/proc.go:255 +0x227 fp=0xc00029ffe0 sp=0xc00029ff80 pc=0x4046cc7
runtime.goexit()
    /Users/runner/hostedtoolcache/go/1.17.11/x64/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00029ffe8 sp=0xc00029ffe0 pc=0x40759a1

rax    0x5b12248
rbx    0x5b0ea80
rcx    0x5b0ea80
rdx    0xffffffffffffffc8
rdi    0x5b12230
rsi    0x0
rbp    0x2092567f0
rsp    0x2092567f0
r8     0xe1c
r9     0xe2d
r10    0xffffe000
r11    0x0
r12    0x5b12230
r13    0x5b11ea0
r14    0x4bdff78
r15    0x0
rip    0x46d373e
rflags 0x202
cs     0x2b
fs     0x0
gs     0x0
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...       7 completed.

I've done some research on what this issue could be, but I'm not 100% on the cause. Clearly, it's crashing during the ttf.Init() function call, but I'm not really sure what to make of that. It should be that Rosetta can handle all Intel code and translate it to ARM code on program first run, right?

I could use some direction in case somebody else has run into something similar before?

veeableful commented 2 years ago

Hi @SolarLune, thanks for reporting the issue! I will check if I can reproduce this and fix it. Really cool to see an actual application that uses go-sdl2!

veeableful commented 1 year ago

Hi @SolarLune, would it be possible for you to test the building for darwin/arm64 in the latest v0.4.x branch? I have added static compilation support for darwin/arm64. It seems to work on my Linux machine to cross-compile to the macOS and it runs on my Macbook Air M1 laptop. If it works for you too, I will add the tag for v0.4.26!

veeableful commented 1 year ago

Hi @SolarLune, I have included static libraries for darwin/arm64 in the new v0.4.26 release. Let me know if it works for you!

SolarLune commented 1 year ago

Hello! Sorry for not getting back to you about this; other things have been going on. I'm looking to have somebody test this for me, but nobody's gotten back to me yet. Once they have, I'll let you know if the issue's resolved. Thank you for your patience!

SolarLune commented 1 year ago

Hello, so another M1 user tested and said it still isn't working. Just wanted to ask if I should need to do anything apart from static compiling on Mac?

veeableful commented 1 year ago

Hi @SolarLune, was the executable statically compiled for darwin/arm64 and that wasn't working for the user?