Hi @sven , @Mathias_Westerdahl I have an issue and I wasted a whole day trying to understand whats wrongā¦ andā¦ nothingā¦
I really need your help.
Did you try to use callbacks with android native extensions?
I have a problem with my DefUnityAds extension on Android (On iOS it works without any problems)
It crashes in situation when I try to recieve few callbacks.
It is easy to reproduce with standart DefUnityAds example:
- just run an example on android
- then tap to Initialize button
- then fast tap 2-3 times to ShowAd button.
On iOS it receives few errors by callback - it is internal error of ads skd like ānot initializedā and so onā¦ itās ok.
But on Android it crashes.
The crash is in lua part, something like:
Build fingerprint: 'Xiaomi/nikel/nikel:6.0/MRA58K/V8.2.1.0.MBFMIDL:user/release-keys'
Revision: '0'
ABI: 'arm'
pid: 14358, tid: 14373, name: Thread-13844 >>> com.agulev.test <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '../src/gameobject/comp_script.cpp:212: dmGameObject::UpdateResult dmGameObject::CompScriptUpdate(const dmGameObject::ComponentsUpdateParams&): assertion "top == lua_gettop(L)" failed'
r0 00000000 r1 00003825 r2 00000006 r3 f342c978
r4 f342c980 r5 f342c930 r6 00000000 r7 0000010c
r8 ee91e1d0 r9 f342c56c sl 00000000 fp eea001b0
ip 00000006 sp f342c4d8 lr f7184ebd pc f71872ac cpsr 400e0010
backtrace:
#00 pc 000432ac /system/lib/libc.so (tgkill+12)
#01 pc 00040eb9 /system/lib/libc.so (pthread_kill+32)
#02 pc 0001c81b /system/lib/libc.so (raise+10)
#03 pc 000199cd /system/lib/libc.so (__libc_android_abort+34)
#04 pc 00017580 /system/lib/libc.so (abort+4)
#05 pc 0001b42f /system/lib/libc.so (__libc_fatal+16)
#06 pc 00019a55 /system/lib/libc.so (__assert2+20)
#07 pc 000c6b2c /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN12dmGameObject16CompScriptUpdateERKNS_22ComponentsUpdateParamsE+212)
#08 pc 000b5d90 /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN12dmGameObject6UpdateEPNS_10CollectionEPKNS_13UpdateContextE+764)
#09 pc 0009ecfc /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN8dmEngine4StepEPNS_6EngineE+1268)
#10 pc 00101e5c /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN10dmGraphics18RunApplicationLoopEPvPFvS0_EPFiS0_E+20)
#11 pc 000a152c /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN8dmEngineL7InitRunEPN15dmEngineService13EngineServiceEiPPcPFvPNS_6EngineEPvES9_S7_+168)
#12 pc 000a15cc /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_ZN8dmEngine6LaunchEiPPcPFvPNS_6EngineEPvES6_S4_+72)
#13 pc 0009d964 /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_Z11engine_mainiPPc+112)
#14 pc 0009bcb4 /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (main+24)
#15 pc 0023cb9c /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (_glfwPreMain+236)
#16 pc 0009bcdc /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (android_main+20)
#17 pc 0023d3bc /data/app/com.agulev.test-1/lib/arm/libDefUnityAds.so (android_app_entry+176)
#18 pc 000407bb /system/lib/libc.so (_ZL15__pthread_startPv+30)
#19 pc 0001a051 /system/lib/libc.so (__start_thread+6)
It is almost all time assertion problem but in different places.
I thougth that the problem is in my code, but:
- It works perfect on iOS;
- Second strange thing, I made few logs:
dmLogInfo("top %i",top);
lua_rawgeti(L, LUA_REGISTRYINDEX, defUtoLua->listener.m_Callback);
lua_rawgeti(L, LUA_REGISTRYINDEX, defUtoLua->listener.m_Self);
lua_pushvalue(L, -1);
dmLogInfo("top1 %i",lua_gettop(L));
dmScript::SetInstance(L);
dmLogInfo("top2 %i",lua_gettop(L));
lua_pushnumber(L, type_of_msg);
dmLogInfo("top3 %i",lua_gettop(L));
int count_table_elements = 1;
if (key_2 != NULL){
count_table_elements = 2;
}
lua_createtable(L, 0, count_table_elements);
dmLogInfo("top4 %i",lua_gettop(L));
luaL_push_pair_str_str(L, key_1, value_1);
if (key_2 != NULL){
luaL_push_pair_str_num(L, key_2, value_2);
}
dmLogInfo("top5 %i",lua_gettop(L));
int ret = lua_pcall(L, 3, LUA_MULTRET, 0);
dmLogInfo("top6 %i",lua_gettop(L));
if (ret != 0) {
dmLogError("Error running defUtoLua callback: %s", lua_tostring(L, -1));
lua_pop(L, 1);
}
dmLogInfo("top7 %i",lua_gettop(L));
and receive next result:
INFO:DEFAULT: top 0
INFO:DEFAULT: top1 3
INFO:DEFAULT: top2 5 --between top1 and top2 only dmScript::SetInstance(L); - WHY STACK IS SO BIG? O_o
INFO:DEFAULT: top3 1
INFO:DEFAULT: top4 2
INFO:DEFAULT: top5 2
the same trace is on ios almost all time
INFO:DEFAULT: top1 3
INFO:DEFAULT: top2 2
INFO:DEFAULT: top3 3
INFO:DEFAULT: top4 4
INFO:DEFAULT: top5 4
On iOS I have stable trace of stack size all the time.
On Android first and second time - itās ok, but after then it randomly changes size of stack (it is not all time place between top1 and top2).
It looks like something changing stack in other thread or something like this. I canāt explain and canāt solve this problem (
Sorry for this long post, I hope you understand what I mean.
I reread all c++/lua docs, recheck all methods and ask @britzl about lua_gettop ā¦ Nothing helpsā¦
Hope you can help me, thank you.