hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.02k stars 660 forks source link

internal/graphicsdriver/opengl/gl: crash on Galaxy A02s #3052

Closed hajimehoshi closed 3 months ago

hajimehoshi commented 3 months ago

Ebitengine Version

v2.8.0-alpha.2

Operating System

Go Version (go version)

go version go1.22.4 darwin/arm64

What steps will reproduce the problem?

Run an Android application with Ebitengine on Galaxy A02s

What is the expected result?

No crash

What happens instead?

Crash on launching

java.lang.RuntimeException: "gl: failed to load libGL.so and libGLESv2.so"
     FATAL EXCEPTION: main
Process: com.rpgsnack.dreams, PID: 2892
java.lang.RuntimeException: "gl: failed to load libGL.so and libGLESv2.so"
    at com.rpgsnack.tsugunai.RuntimeView.handleError(RuntimeView.java:263)
    at com.rpgsnack.tsugunai.RuntimeView.onErrorOnGameUpdate(RuntimeView.java:253)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView.onErrorOnGameUpdate(EbitenSurfaceView.java:99)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView.access$000(EbitenSurfaceView.java:31)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView$EbitenRenderer$1.run(EbitenSurfaceView.java:53)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8751)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Anything else you feel useful to add?

I've confirmed this on Firebase Test Lab with our Ebitengine application.

hajimehoshi commented 3 months ago

With Ebitengine 856b339298bc19ccd814c8ed2dd283ab4a028e2d:

java.lang.RuntimeException: "gl: failed to load libGL.so and libGLESv2.so: libGLESv2.so: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.2: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.1: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.0: dlopen failed: invalid flags to dlopen: 101"
     FATAL EXCEPTION: main
Process: com.rpgsnack.dreams, PID: 1995
java.lang.RuntimeException: "gl: failed to load libGL.so and libGLESv2.so: libGLESv2.so: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.2: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.1: dlopen failed: invalid flags to dlopen: 101, libGLESv2.so.0: dlopen failed: invalid flags to dlopen: 101"
    at com.rpgsnack.tsugunai.RuntimeView.handleError(RuntimeView.java:263)
    at com.rpgsnack.tsugunai.RuntimeView.onErrorOnGameUpdate(RuntimeView.java:253)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView.onErrorOnGameUpdate(EbitenSurfaceView.java:99)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView.access$000(EbitenSurfaceView.java:31)
    at com.rpgsnack.runtime.mobile.EbitenSurfaceView$EbitenRenderer$1.run(EbitenSurfaceView.java:53)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8751)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
hajimehoshi commented 3 months ago

https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/include/dlfcn.h

My guess is that __LP64__ is not defined on this device, but I am not 100% sure.

/CC @TotallyGamerJet

hajimehoshi commented 3 months ago

Even with C's RTLD definitions, another crash happened.

Build fingerprint: 'samsung/a02qnnxx/a02q:12/SP1A.210812.016/A025FXXU6CWE2:user/release-keys'
Revision: '0'
ABI: 'arm'
Processor: '-1'
Timestamp: 2024-07-31 11:44:27.440401246-0700
Process uptime: 167s
Cmdline: com.rpgsnack.dreams
pid: 15685, tid: 20768, name: GLThread 566  >>> com.rpgsnack.dreams <<<
uid: 10241
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x18
Cause: null pointer dereference
    r0  88761020  r1  00000018  r2  00000018  r3  00000000
    r4  00000018  r5  00000001  r6  78ba92e0  r7  00000018
    r8  bb8e2f9c  r9  bb8e18c0  r10 00000004  r11 00001405
    ip  e41ce9d0  sp  85692af8  lr  c9a0d649  pc  e4172534
backtrace:
      #00 pc 00062534  /apex/com.android.runtime/lib/bionic/libc.so (__memcpy_a53+152) (BuildId: 775d2b96242725b513297af37a26150c)
      #01 pc 000b3645  /vendor/lib/egl/libGLESv2_adreno.so (!!!0000!77df12deb6a622478efa8fb9929034!5441528417!+456) (BuildId: 638d93a8f2e34d08525f24261b1b7723)
      #02 pc 000edd2b  /vendor/lib/egl/libGLESv2_adreno.so (!!!0000!fd7498413de80da11b66fb6ac2c9ef!5441528417!+146) (BuildId: 638d93a8f2e34d08525f24261b1b7723)
      #03 pc 0004a22f  /vendor/lib/egl/libGLESv2_adreno.so (glDrawElements+42) (BuildId: 638d93a8f2e34d08525f24261b1b7723)
      #04 pc 00c415d4  /data/app/~~qZoibUQJ8Abn2b1Yny8m4A==/com.rpgsnack.dreams-hSUawpgAcFjmhm2oLjoGgQ==/split_config.armeabi_v7a.apk (syscall15+156)

I'll try to replace all the dlopen part with C version later.

hajimehoshi commented 3 months ago

In v2.7, PureGo is not used for this part https://github.com/hajimehoshi/ebiten/blob/2.7/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go

TotallyGamerJet commented 3 months ago

A quick solution is to just revert the change in procaddr_linbsd. I wonder if this is a sign that arguments are not being passed correctly in arm64. Perhaps trying purego.SyscallN instead of RegisterFunc. It’s unclear from the last error if this is a call to an OpenGL function or to Dlopen

hajimehoshi commented 3 months ago

I've confirmed that the fix worked on Test Lab.

hajimehoshi commented 3 months ago

I've almost reverted the Android part, but not non-Android Linux part. So, there might still be an issue on Linux, but I don't know what machines an issue. On Linux, the constants RTLD_* always seem the same, so this might be different from Android.

hajimehoshi commented 3 months ago

https://community.infiniteflight.com/t/i-cannot-download-if-because-its-not-compatible/710435/4

This is due to your device’s OS. Despite your processor being a 64-bit model, which is now a requirement for Infinite Flight to be installed, your phone has a 32-bit version of Android. Why Samsung has done it for this device is beyond me, however, it means that you will not be able to install IF on your Samsung Galaxy A02s, as your phone is recognized as a 32-bit one.