Intermittent Corona SDK Crash on Android

Every now and then my app will just crash when running on a Droid or Iconia Tab. On the Tab I managed to get the logcat, which I’ve appended to this post.

I don’t have a crash stack going back to my app so I’m not sure if it’s me, but it’s not happening on iOS or in the simulator. Anyone seen something similar or have any ideas what the culprit might be?

W/dalvikvm(12216): ReferenceTable overflow (max=512)  
W/dalvikvm(12216): Last 10 entries in JNI local reference table:  
W/dalvikvm(12216): 502: 0x408af600 cls=[B (2980 bytes)  
W/dalvikvm(12216): 503: 0x408af600 cls=[B (2980 bytes)  
W/dalvikvm(12216): 504: 0x40898420 cls=[B (1892 bytes)  
W/dalvikvm(12216): 505: 0x40898420 cls=[B (1892 bytes)  
W/dalvikvm(12216): 506: 0x408b01a8 cls=[B (2516 bytes)  
W/dalvikvm(12216): 507: 0x408b01a8 cls=[B (2516 bytes)  
W/dalvikvm(12216): 508: 0x40835178 cls=Ljava/lang/Class; 'Lcom/ansca/corona/NativeToJavaBridge;' (164 bytes)  
W/dalvikvm(12216): 509: 0x40821958 cls=Ljava/lang/String; (28 bytes)  
W/dalvikvm(12216): 510: 0x401c0220 cls=Landroid/graphics/Bitmap$Config; (20 bytes)  
W/dalvikvm(12216): 511: 0x408fb0c0 cls=[B (4194324 bytes)  
W/dalvikvm(12216): JNI local reference table summary (512 entries):  
W/dalvikvm(12216): 1 of Ljava/lang/Class; 164B  
W/dalvikvm(12216): 18 of [B 1268B (9 unique)  
W/dalvikvm(12216): 24 of [B 1420B (12 unique)  
W/dalvikvm(12216): 6 of [B 1428B (2 unique)  
W/dalvikvm(12216): 24 of [B 1580B (12 unique)  
W/dalvikvm(12216): 48 of [B 1732B (22 unique)  
W/dalvikvm(12216): 56 of [B 1892B (26 unique)  
W/dalvikvm(12216): 40 of [B 2044B (19 unique)  
W/dalvikvm(12216): 50 of [B 2204B (24 unique)  
W/dalvikvm(12216): 46 of [B 2356B (22 unique)  
W/dalvikvm(12216): 46 of [B 2516B (22 unique)  
W/dalvikvm(12216): 32 of [B 2668B (15 unique)  
W/dalvikvm(12216): 36 of [B 2828B (17 unique)  
W/dalvikvm(12216): 32 of [B 2980B (16 unique)  
W/dalvikvm(12216): 6 of [B 3140B (3 unique)  
W/dalvikvm(12216): 20 of [B 3292B (10 unique)  
W/dalvikvm(12216): 8 of [B 3452B (4 unique)  
W/dalvikvm(12216): 10 of [B 3604B (5 unique)  
W/dalvikvm(12216): 4 of [B 3764B (2 unique)  
W/dalvikvm(12216): 2 of [B 4076B (1 unique)  
W/dalvikvm(12216): 1 of [B 4194324B  
W/dalvikvm(12216): 1 of Ljava/lang/String; 28B  
W/dalvikvm(12216): 1 of Landroid/graphics/Bitmap$Config; 20B  
W/dalvikvm(12216): Memory held directly by tracked refs is 4752564 bytes  
E/dalvikvm(12216): Failed adding to JNI local ref table (has 512 entries)  
I/dalvikvm(12216): "GLThread 12" prio=5 tid=11 RUNNABLE  
I/dalvikvm(12216): | group="main" sCount=0 dsCount=0 obj=0x40840480 self=0x1395b8  
I/dalvikvm(12216): | sysTid=12226 nice=0 sched=0/0 cgrp=default handle=767712  
I/dalvikvm(12216): | schedstat=( 43976157000 12323555000 42534 ) utm=3915 stm=482 core=0  
I/dalvikvm(12216): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)  
I/dalvikvm(12216): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)  
I/dalvikvm(12216): at com.ansca.corona.NativeToJavaBridge.createBitmap(NativeToJavaBridge.java:624)  
I/dalvikvm(12216): at com.ansca.corona.NativeToJavaBridge.getBitmapAsset(NativeToJavaBridge.java:686)  
I/dalvikvm(12216): at com.ansca.corona.NativeToJavaBridge.callGetBitmapAsset(NativeToJavaBridge.java:904)  
I/dalvikvm(12216): at com.ansca.corona.JavaToNativeShim.nativeRender(Native Method)  
I/dalvikvm(12216): at com.ansca.corona.JavaToNativeShim.render(JavaToNativeShim.java:89)  
I/dalvikvm(12216): at com.ansca.corona.Controller.onDrawFrame(Controller.java:230)  
I/dalvikvm(12216): at com.ansca.corona.CoronaRenderer.onDrawFrame(CoronaRenderer.java:59)  
I/dalvikvm(12216): at android.opengl.derived.SwapGLSurfaceView$GLThread.guardedRun(SwapGLSurfaceView.java:913)  
I/dalvikvm(12216): at android.opengl.derived.SwapGLSurfaceView$GLThread.run(SwapGLSurfaceView.java:773)  
I/dalvikvm(12216):   
E/dalvikvm(12216): VM aborting  
I/DEBUG ( 81): \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\* \*\*\*  
I/DEBUG ( 81): Build fingerprint: 'acer/picasso\_comgen2/picasso:3.2/HTJ85B/1315474096:user/release-keys'  
I/DEBUG ( 81): pid: 12216, tid: 12226 \>\>\> com.undercoverdoxie.alphabatty \<\<\<  
I/DEBUG ( 81): signal 11 (SIGSEGV), code 1 (SEGV\_MAPERR), fault addr deadd00d  
I/DEBUG ( 81): r0 deadd00d r1 00194b50 r2 00000026 r3 00000000  
I/DEBUG ( 81): r4 411d3918 r5 00000000 r6 001395b8 r7 00139604  
I/DEBUG ( 81): r8 ad3598cc r9 0095e678 10 00000000 fp 00000001  
I/DEBUG ( 81): ip 00000000 sp 5983d050 lr afee0c88 pc aca0db16 cpsr 20000030  
I/DEBUG ( 81): d0 42c8000041c7e560 d1 447a00000072b8b0  
I/DEBUG ( 81): d2 00000000c47a0000 d3 000000003f000000  
I/DEBUG ( 81): d4 4704c00000000000 d5 00000000000084c0  
I/DEBUG ( 81): d6 01cb1fe000000000 d7 000000184e334093  
I/DEBUG ( 81): d8 4090000000000000 d9 4090000000000000  
I/DEBUG ( 81): d10 0000000000000000 d11 0000000000000000  
I/DEBUG ( 81): d12 0000000000000000 d13 0000000000000000  
I/DEBUG ( 81): d14 0000000000000000 d15 0000000000000000  
I/DEBUG ( 81): scr 60000013  
I/DEBUG ( 81):   
I/DEBUG ( 81): #00 pc 0003db16 /system/lib/libdvm.so (dvmAbort)  
I/DEBUG ( 81): #01 pc 0004158e /system/lib/libdvm.so  
I/DEBUG ( 81): #02 pc 00042df4 /system/lib/libdvm.so  
I/DEBUG ( 81): #03 pc 00057660 /system/lib/libandroid\_runtime.so (\_Z17getMimeTypeStringP7\_JNIEnvN14SkImageDecoder6FormatE)  
I/DEBUG ( 81): #04 pc 00057e34 /system/lib/libandroid\_runtime.so  
I/DEBUG ( 81): #05 pc 000581b4 /system/lib/libandroid\_runtime.so  
I/DEBUG ( 81): #06 pc 00011c74 /system/lib/libdvm.so  
I/DEBUG ( 81):   
I/DEBUG ( 81): libc base address: afed0000  
I/DEBUG ( 81):   
I/DEBUG ( 81): code around pc:  
I/DEBUG ( 81): aca0daf4 b5104a0b 447a4479 ec46f7d3 f7d32000   
I/DEBUG ( 81): aca0db04 4b08ed5e 681b447b b1036c1b 48024798   
I/DEBUG ( 81): aca0db14 70022226 eda6f7d3 deadd00d 0003f430   
I/DEBUG ( 81): aca0db24 00041035 0005c9b8 4b09b40e aa03b503   
I/DEBUG ( 81): aca0db34 681b447b 1b04f852 92016b9b 4798b10b   
I/DEBUG ( 81):   
I/DEBUG ( 81): code around lr:  
I/DEBUG ( 81): afee0c68 02800016 08bd87f0 e5964000 e5967000   
I/DEBUG ( 81): afee0c78 e2144903 1a00000e e5965000 ebffed9e   
I/DEBUG ( 81): afee0c88 e2055a02 e3853001 e1500003 0a000006   
I/DEBUG ( 81): afee0c98 e5865000 e1a00006 e1a01005 e3a02001   
I/DEBUG ( 81): afee0ca8 ebfffee4 e1a00004 e8bd87f0 e3a00000   
I/DEBUG ( 81):   
I/DEBUG ( 81): stack:  
I/DEBUG ( 81): 5983d010 00000000   
I/DEBUG ( 81): 5983d014 afee829d /system/lib/libc.so  
I/DEBUG ( 81): 5983d018 aff116ec   
I/DEBUG ( 81): 5983d01c aff1683c   
I/DEBUG ( 81): 5983d020 00000000   
I/DEBUG ( 81): 5983d024 afee94a5 /system/lib/libc.so  
I/DEBUG ( 81): 5983d028 aff1153c   
I/DEBUG ( 81): 5983d02c 00000000   
I/DEBUG ( 81): 5983d030 001395b8   
I/DEBUG ( 81): 5983d034 00139604   
I/DEBUG ( 81): 5983d038 ad3598cc   
I/DEBUG ( 81): 5983d03c afee82bb /system/lib/libc.so  
I/DEBUG ( 81): 5983d040 411d3918   
I/DEBUG ( 81): 5983d044 00000000   
I/DEBUG ( 81): 5983d048 df002777   
I/DEBUG ( 81): 5983d04c e3a070ad   
I/DEBUG ( 81): #00 5983d050 411d3918   
I/DEBUG ( 81): 5983d054 aca11593 /system/lib/libdvm.so  
I/DEBUG ( 81): #01 5983d058 ad34b763 /system/lib/libandroid\_runtime.so  
I/DEBUG ( 81): 5983d05c 001395b8   
I/DEBUG ( 81): 5983d060 411d3918   
I/DEBUG ( 81): 5983d064 0013e5d0   
I/DEBUG ( 81): 5983d068 ad3598cc   
I/DEBUG ( 81): 5983d06c aca12df9 /system/lib/libdvm.so  

[import]uid: 44812 topic_id: 16656 reply_id: 316656[/import]

I’m not an Android expert but what’s going on in the app when that happens? Just asking as it might easier to locate the cause that way…

Fx, I had a crash when the game runs system.vibrate command and fixed it by adding “android.permission.VIBRATE” to the build.settings… [import]uid: 10478 topic_id: 16656 reply_id: 62207[/import]

I have no idea what’s happening in my game when this happens, since there’s no crash stack for me to see. It seems to be somewhat intermittent and random. [import]uid: 44812 topic_id: 16656 reply_id: 62228[/import]

looks like u r trying to load an image that is not there or the image is not capitalized properly.

filenames on devices are case sensitive

Foo.png is not the same as “foo.png”

display.newImage(“Foo.png”) will fail if the file name is ‘foo.png’

.c [import]uid: 24 topic_id: 16656 reply_id: 62278[/import]

Thanks for the response Carlos – what are you basing this on? Why would it kill the process instead of generating an exception and propagating it back to my program? I’ve double checked my filenames and asset strings and everything looks correct, my capitalization is consistent.

Is it possible that the “getMimeType” has something to do with it – is it possible that an image is somehow in the wrong format and causing a crash? Would an indexed PNG or an embedded ICC profile actually cause a crash instead of just failing to load? [import]uid: 44812 topic_id: 16656 reply_id: 62281[/import]

indexed png’s will *NOT* work - ICC profiles embedded are an offshoot. they work/don’t work. I always say remove ICC

you need to use 32 big png’s.

why?

what led me to the bitmapcode. oh i don’t know maybe

android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

before it crashes…

c. [import]uid: 24 topic_id: 16656 reply_id: 62287[/import]

To be clear Carlos, I don’t have any indexed PNG or ICC profiles (that I’m aware of =) ) I’m just trying to figure out if they would cause this type of crash or if they would simply not appear. My understanding is that unsupported or missing files would result in no image or an exception with callstack, not this type of crash.
[import]uid: 44812 topic_id: 16656 reply_id: 62345[/import]

I just ran imagemagick -identify on all my PNG files (and I only use PNG), and all are confirmed to be RGB, with the exception of my masks (which work on Android and iOS and in the simulator). In addition I confirmed that none of them have an iCCP PNG chunk.

The symptom here is that things are crashing because the reference table is overflowing?

“ReferenceTable overflow (max=512)”

What’s leading to the overflow (i.e. some references are left dangling) is what I’m trying to figure out.
[import]uid: 44812 topic_id: 16656 reply_id: 62368[/import]

hmm…
Check all your file names again… just a suggestion…

make sure to check the file extentions for case…

I had a hell of a problem with crashes at one point and it was the result of a file name like “mypic.PNG”…
windows will hide the file extention from you or just report what it is(losing the formatting) so it is not clear that it is wrong… the extention being hidden… it is a pain to change the format of the extention as well… I opened my trouble graghic and did a save as to correct it.

[import]uid: 40100 topic_id: 16656 reply_id: 62388[/import]

how many assets do you have?

if its more than 512 you need the latest version of corona (519) public(whatever the id is) or the latest daily build.

c. [import]uid: 24 topic_id: 16656 reply_id: 62425[/import]

Hi Carlos,

I only have about 100 assets total between png and sound, and I’m using the latest build.

I don’t expect you guys to debug my own problems, I’m just trying to figure out where the source might be so I can narrow it down. This crash happens very rarely for me and only on devices.

[import]uid: 44812 topic_id: 16656 reply_id: 62430[/import]

Having the same problem and have spent the last several days researching what might be happening.
I concluded that the garbage collection process can be quite slow and if you are creating and removing a lot of assets before garbage collection can take place, you will hit the magic number of 512 and the app will crash. I verified this scenario with several pieces of code.

This code will crash Android because 512 assets were created before garbage collection can do it’s thing.

for i = 1, 512, 1 do  
local tempText = display.newText("abc", 0, 0, native.systemFont, 12 )  
  
-- do something here with tempText  
-- I'm using it find the width in pixels of a string of text  
  
-- now remove tempText and do garbage collection  
tempText:removeSelf()  
tempText = nil  
collectgarbage("collect")  
end  

But this code runs fine because garbage collection has time to work however, it takes a long time to run.

local i = 0  
local tempTimer  
  
local function createSomeText()  
  
 local tempText = display.newText("abc", 0, 0, native.systemFont, 12 )  
 -- do something here with tempText  
  
 -- now remove tempText and do garbage collection  
 tempText:removeSelf()  
 tempText = nil  
 collectgarbage("collect")  
  
 -- see if we are done  
 i = i+1  
 if i \>= 512 then   
 timer.cancel(tempTimer)   
 local endText = display.newText("..End", 20, 50, native.systemFont, 20 )  
 end  
end  
  
tempTimer = timer.performWithDelay(1,createSomeText,0)  

I’ve done all I know to do at this point and now I need some help from from the pros.

-Jeff [import]uid: 14119 topic_id: 16656 reply_id: 62777[/import]

Thanks for the info. Sounds like if I do a periodic GC that this might help me out, but since I don’t have a solid repro case I’m not sure if that’s going to be an actual solution.
[import]uid: 44812 topic_id: 16656 reply_id: 62779[/import]