ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
690 stars 158 forks source link

[AssaultCube] crash in draw_renderlist #283

Closed drian0 closed 3 years ago

drian0 commented 3 years ago

Hello all

First of all, thanks for providing this library. This is really awesome!

We are currently in progress of porting AssaultCube to Android. At the moment the game runs a bit unstable as once in a while we experience a crash within the GL4ES library (master branch).

Please find the stacktrace attached: Capture

It happens from time to time and we do not know a way to reliably reproduce it.

We are using the following hints for GL4ES:

    glHint(GL_BATCH_HINT_GL4ES, 1000);
    glHint(GL_RECYCLEFBO_HINT_GL4ES, 1);

Are there any steps we could take to mitigate this problem? What information should we trace to support resolving this issue?

Thank you very much for your help.

ptitSeb commented 3 years ago

Oh, AssaultCube on Android, nice!

Can you build gl4es with debug info? draw_renderlist is a huge function, the line of the crash would be helpfull.

(did you workaround the problem with depth reading that is not really possible on GLES hardware? well, it should be possible on ES3+ harware, but still undvised as it might slow down things)

drian0 commented 3 years ago

Thanks for your quick reply. I will try to build it with debug info and let you know once I can obtain a more detailed stack trace.

Yes, the depth calculation with glReadPixels did not work initially. We had a similar problem already 20 years ago with some buggy ATI drivers on linux. The funny story: When I googled for a solution I couldn't believe what I saw, here on your github issue list someone had ported cube and assaultcube to Amiga OS and had encountered and resolved this specific issue already. That's cool.

kas1e commented 3 years ago

@drian0

I couldn't believe what I saw, here on your github issue list someone had ported cube and assaultcube to Amiga OS and had encountered and resolved this specific issue already. That's cool.

Yeah, that was me :) Cube issues were fixed on their forum, and then someone helps me with Assault Cube on the assault's forum as well. But it was about 10 years ago, not 20 :)

Now I tried to run Cube2: Sauerbraten on gl4es on amigaos4, and while it all builds and run, I still have issues with it. But need to check if they gl4es related at all (by building it on PPC Linux firstly).

drian0 commented 3 years ago

@kas1e That's great, thank you :) Btw, Cube2 uses shaders only without fixed pipeline functions I think - so I guess it will be difficult (or impossible?) to get it wo work decently with GL4ES as I understood that it does not fully support shaders.

@ptitSeb Please find below a more detailed stack trace. Is this sufficient?


*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> net.cubers.assaultcube <<<

backtrace:
  #00  pc 000000000017c834  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (realize_glenv) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/fpe.c:1112)
  #00  pc 000000000017ebdc  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (fpe_glDrawElements) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/fpe.c:800)
  #00  pc 000000000019d188  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.10) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/listdraw.c:751)
  #00  pc 000000000018c414  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (gl4es_flush) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/gl4es.c:1003)
  #00  pc 00000000001c878c  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (gl4es_glBindTexture) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/texture_params.c:192)
  #00  pc 00000000000f9db0  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (render_particles(int, int)) (SourceCode: C:/DEV/ac/source/src/renderparticles.cpp:298)
  #00  pc 00000000000e01fc  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (drawreflection(float, int, int, float, bool)) (SourceCode: C:/DEV/ac/source/src/rendergl.cpp:795)
  #00  pc 00000000000e1ae4  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (gl_drawframe(int, int, float, float, int)) (SourceCode: C:/DEV/ac/source/src/rendergl.cpp:1270)
  #00  pc 00000000000bd7e0  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.29) (SourceCode: C:/DEV/ac/source/src/main.cpp:1466)
  #00  pc 000000000009e034  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/split_config.arm64_v8a.apk!lib/arm64-v8a/libSDL2.so (offset 0x1000) (Java_org_libsdl_app_SDLActivity_nativeRunMain)
  #00  pc 0000000000003644  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/oat/arm64/base.odex (art_jni_trampoline+228)
  #00  pc 00000000001375b8  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_static_stub+568)
  #00  pc 000000000014600c  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+276)
  #00  pc 00000000002e2d7c  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384)
  #00  pc 00000000002ddfdc  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+892)
  #00  pc 00000000005a36fc  /apex/com.android.runtime/lib64/libart.so (MterpInvokeStatic+372)
  #00  pc 0000000000131994  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_static+20)
  #00  pc 0000000000007948  /data/app/net.cubers.assaultcube-SEBkhtXjZj2jtEZXF0TjyQ==/oat/arm64/base.vdex (org.libsdl.app.SDLMain.run+168)
  #00  pc 00000000002b4090  /apex/com.android.runtime/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.15450530207560829030)+240)
  #00  pc 0000000000592190  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1032)
  #00  pc 0000000000140468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88)
  #00  pc 00000000001b7b38  /system/framework/arm64/boot.oat (java.lang.Thread.run+72)
  #00  pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548)
  #00  pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244)
  #00  pc 00000000004b05fc  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
  #00  pc 00000000004b1710  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416)
  #00  pc 00000000004f26c8  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176)
  #00  pc 00000000000e6f20  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36)
  #00  pc 00000000000850c8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
drian0 commented 3 years ago

@ptitSeb One more stacktrace below. Is it OK if I post them to the same issue here?

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 0 >>> net.cubers.assaultcube <<<

backtrace:
  #00  pc 000000000039e940  /vendor/lib64/egl/libGLESv2_adreno.so
  #00  pc 000000000037fdcc  /vendor/lib64/egl/libGLESv2_adreno.so
  #00  pc 000000000012f090  /vendor/lib64/egl/libGLESv2_adreno.so
  #00  pc 00000000001884b0  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (fpe_glDrawElements) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/fpe.c:810)
  #00  pc 00000000001a89a8  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.24) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/listdraw.c:751)
  #00  pc 00000000000fd578  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (vertmodel::mesh::render(animstate&, vertmodel::anpos&, vertmodel::anpos*, float)) (SourceCode: C:/DEV/ac/source/android/app/src/main/cpp/../../../../../src/vertmodel.h:473)
  #00  pc 00000000000fce08  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (vertmodel::part::render(int, int, float, int, dynent*)) (SourceCode: C:/DEV/ac/source/android/app/src/main/cpp/../../../../../src/vertmodel.h:895)
  #00  pc 0000000000102568  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (md3::render(int, int, float, int, vec const&, float, float, float, dynent*, modelattach*, float)) (SourceCode: C:/DEV/ac/source/android/app/src/main/cpp/../../../../../src/md3.h:196)
  #00  pc 00000000000f8d34  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.453) (SourceCode: C:/DEV/ac/source/src/rendermodel.cpp)
  #00  pc 00000000000b580c  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (rendermapmodels()) (SourceCode: C:/DEV/ac/source/src/entities.cpp:80)
  #00  pc 00000000000e910c  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.31) (SourceCode: C:/DEV/ac/source/src/rendergl.cpp:793)
  #00  pc 00000000000ea59c  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (gl_drawframe(int, int, float, float, int)) (SourceCode: C:/DEV/ac/source/src/rendergl.cpp:1273)
  #00  pc 00000000000c1ad4  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) ($d.29) (SourceCode: C:/DEV/ac/source/src/main.cpp:1426)
  #00  pc 000000000009e034  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/split_config.arm64_v8a.apk!lib/arm64-v8a/libSDL2.so (offset 0x1000) (Java_org_libsdl_app_SDLActivity_nativeRunMain)
  #00  pc 0000000000004754  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/oat/arm64/base.odex (art_jni_trampoline+228)
  #00  pc 00000000001375b8  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_static_stub+568)
  #00  pc 000000000014600c  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+276)
  #00  pc 00000000002e2d7c  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384)
  #00  pc 00000000002ddfdc  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+892)
  #00  pc 00000000005a36fc  /apex/com.android.runtime/lib64/libart.so (MterpInvokeStatic+372)
  #00  pc 0000000000131994  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_static+20)
  #00  pc 0000000000034164  /data/app/net.cubers.assaultcube-dHocWEk1vizaEKwCTA1TQg==/oat/arm64/base.vdex (org.libsdl.app.SDLMain.run+168)
  #00  pc 00000000002b4090  /apex/com.android.runtime/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.15450530207560829030)+240)
  #00  pc 0000000000592190  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1032)
  #00  pc 0000000000140468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88)
  #00  pc 00000000001b7b38  /system/framework/arm64/boot.oat (java.lang.Thread.run+72)
  #00  pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548)
  #00  pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244)
  #00  pc 00000000004b05fc  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
  #00  pc 00000000004b1710  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416)
  #00  pc 00000000004f26c8  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176)
  #00  pc 00000000000e6f20  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36)
  #00  pc 00000000000850c8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
ptitSeb commented 3 years ago

The backtrace seems detailled enough, but on first look I don't see an obvious reason for it to crash, especialy the 1st one, the code looks good to me.

drian0 commented 3 years ago

So we are running an open beta of AC mobile now. You can get the app here if you want to see it. Please note that the link only works when opened from an Android device.

We do now have more data records about the crash. It turns out that most of the time the crash happens at glCallList(..) The stacktraces always end up with a SEGV_MAPERR here:

/data/app/net.cubers.assaultcube-esEW2DUHc2jWl4EwD4v8Pw==/split_config.arm64_v8a.apk!lib/arm64-v8a/libmain.so (offset 0x2ef000) (draw_renderlist) (SourceCode: C:\DEV\ac\source\android\app\src\main\cpp\gl4es/./src/gl/listdraw.c:742)

Could you take another look at this line and/or could you tell me what additional data I could collect to nail this down?

Thank you very much for your help!

ptitSeb commented 3 years ago

Can you try to get the value of list->ilen (and maybe list->len too if possible) at the moment of the crash?

drian0 commented 3 years ago

Let me see if I can collect this info.

drian0 commented 3 years ago

Unfortunately we could not resolve the issue because it happens on other user's devices according to our crash logs and we can not reproduce it on our development devices (it does not happen often enough to dump/analyze it).

The way we resolved this now is by disabling the use of display lists altogether. It seems that this has fixed the problem for us, we have no more crashes since then.

Thank you very much for your help though.

AssaultCube Mobile is now publicly available here. If you would like to feature us on your MEDIA page I can send over a screenshot.

ptitSeb commented 3 years ago

Ah yeah, please send a screenshot and I'll add to MEDIA.

The workaround works, but I'm guessing it lose some fps (maybe it doesn't mater much because of the power of curent devices)

drian0 commented 3 years ago

Here you go:

unnamed

Thank you.

ptitSeb commented 3 years ago

I think commit bfc764db696982853cbe18df723313b385cfcb32 may have fixed the VBO issue. Can you test it?