supertuxkart / stk-code

The code base of supertuxkart
Other
4.54k stars 1.06k forks source link

Get rid of the exit(0) at the end of android_main() function #3000

Closed deveee closed 3 years ago

deveee commented 7 years ago
  native: pc 0000000000315722  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so (_ZN19ShaderBasedRenderer6renderEf+661)
  native: pc 0000000000382917  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so (_ZN9IrrDriver6updateEf+134)
  native: pc 000000000027b677  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so (_ZN8MainLoop3runEv+382)
  native: pc 0000000000242c43  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so (main+1642)
  native: pc 000000000027b8f7  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so (android_main+42)
  native: pc 00000000009f065b  /data/app/org.supertuxkart.stk-1/lib/arm/libmain.so
  native: pc 0000000000047f93  /system/lib/libc.so (_ZL15__pthread_startPv+22)
  native: pc 000000000001a161  /system/lib/libc.so (__start_thread+6)

It's precisely src/graphics/shader_based_renderer.cpp:815 that is:

computeMatrixesAndCameras(camnode, m_rtts->getWidth(), m_rtts->getHeight());

It's most frequent crash on android that happens on multiple devices (it happened for 7 different people since 0.9.3-rc1).

deveee commented 7 years ago

For me the only possibility is that world is deleted, but m_world is not set to null. And then m_rtt is null. But anyway it seems unlikely, because m_world is set to null in destructor...

deveee commented 7 years ago

I think that in some cases (for example when STK window is in background for a long time) system kills the activity, but doesn't unload our .so library. In this case global variables are uninitialized in next run, so m_world is not null and it will cause a crash.

Typically it doesn't happen, because there is exit(0) at the end of android_main() function.

Actually I found a way how to avoid the exit(0) at the end of main function and make sure that all global variables are always initialized. We can just use small libmain.so file that only loads our libstk.so library, then executes main() and unloads libstk.so. But I think that it's too big/unsafe modification for 0.9.3.

Benau commented 3 years ago

can you try this apk: https://github.com/Benau/stk-code/releases/download/preview/SuperTuxKart-git20211004.apk

If it crashes on startup (complain about HID / USB) then this: https://github.com/Benau/stk-code/releases/download/preview/SuperTuxKart-git20211004-fix.apk

Bascially try quiting stk and then restart and see if it starts properly again, and https://github.com/Benau/stk-code/commit/835154bde227c7863d61b0fab5f937022d269678 so it may less likely to crash in background

btw only r22 ndk will work, 23 not supported by current mbedtls (fixed in master), 24 removed android 16 support

Benau commented 3 years ago

test in android 4.2 btw (and more devices better if has time)

tested in 3 phones + 1 emulator all working