So to give a brief overview:
We created a game utilizing the storyboard API. We have several scenes in the game, and each time we switch from one scene to another, we call storyboard.removeScene(scene). Technically, this should free all texture memory and Lua memory. This implementation works as we tested it on the iPhone 4, iPad 2, Mac/Win Simulators, as well as on a HTC Desire Z running Gingerbread, all built using 840.
So we release our game on Google Play and App Store, and started getting bad ratings and feedback because of a bug with assets not loading. We used an ASUS Transformer Prime running ICS to test our app and encountered a bug where some of our game assets do not load, causing the app to hang.
We fired up adb logcat, and discovered the following error:
E/dalvikvm-heap( 4768): Out of memory on a 16777232-byte allocation.
I/dalvikvm( 4768): "GLThread 363" prio=5 tid=13 RUNNABLE
I/dalvikvm( 4768): | group="main" sCount=0 dsCount=0 obj=0x410b1c18 self=0x1abd750
I/dalvikvm( 4768): | sysTid=4784 nice=0 sched=0/0 cgrp=default handle=27830064
I/dalvikvm( 4768): | schedstat=( 87021431000 11326609000 54061 ) utm=7239 stm=1463 core=0
I/dalvikvm( 4768): at com.ansca.corona.NativeToJavaBridge.getBitmapAsset(NativeToJavaBridge.java:~
798)
I/dalvikvm( 4768): at com.ansca.corona.NativeToJavaBridge.callGetBitmapAsset(NativeToJavaBridge.ja
va:1023)
I/dalvikvm( 4768): at com.ansca.corona.JavaToNativeShim.nativeResize(Native Method)
I/dalvikvm( 4768): at com.ansca.corona.JavaToNativeShim.resize(JavaToNativeShim.java:147)
I/dalvikvm( 4768): at com.ansca.corona.CoronaRenderer.onSurfaceChanged(CoronaRenderer.java:37)
I/dalvikvm( 4768): at android.opengl.derived.SwapGLSurfaceView$GLThread.guardedRun(SwapGLSurfaceVi
ew.java:944)
I/dalvikvm( 4768): at android.opengl.derived.SwapGLSurfaceView$GLThread.run(SwapGLSurfaceView.java
:809)
I/dalvikvm( 4768):
I/System.out( 4768): getBitmapAsset: Ran out of memory in the Java VM loading an image (Assets/Backg
rounds/robotbldg@2x.png) of size 2048x2048
I/Corona ( 5969): Lua Runtime Error: lua\_pcall failed with status: 2, error message is:
lid parameter passed to sprite.newSpriteSheetFromData(). Frame overlaps sprite sheet.
First things that ran through our mind was that we had a Texture Memory leak somewhere, or that the asset in question was simply too big to be loaded into Texture Memory. However, further testing showed no memory leaks (both texture or otherwise).
Clearly, this should be the case as we always call a storyboard.removeScene() call when we switch scenes.
So we assumed the asset must be too big to be loaded into texture memory, but all our assets are within the 2048 X 2048 limit. We discovered this bug only occurs when you follow a certain sequence of steps. To elaborate, let me first describe the scenes we have build in the game.
For the purpose of this problem, we focus on 4 scenes in question:
mainmenu.lua - as the name suggests, the main menu scene
loadScene.lua - a transition scene to display a loading screen between scene loads
shop.lua - the shop and IAP scene for our game
game.lua - game scene proper, this is where the asset in question is loaded
When a user starts the game from scratch, and goes from main menu straight into the game, the storyboard scenes transition from:
main.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> game.lua,
we discovered that the assets would load without any errors or crashes, the game runs as intended.
However, if the user starts the game and goes from main menu to shop, then to the game, i.e.:
main.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> shop.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> game.lua,
the above error will occur.
We then assumed that shop.lua was the problem, but:
main.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> game.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> shop.lua -> loadScene.lua -> mainmenu.lua -> loadScene.lua -> game.lua
does not yield any errors.
Now since the game can run normally with assets loading, clearly the asset in question can be loaded into texture memory. If that’s the case, then why is this bug occurring only when we go from the shop scene to game scene from a fresh instance of the app?
TL;DR: we encounter an asset loading problem on certain Android devices, can’t figure out why it happens as it’s not due to texture memory leaks or the asset being too big, but more of the precedence of scenes we goto using the storyboard API. [import]uid: 108204 topic_id: 29558 reply_id: 329558[/import]