Out of memory problem

Hello,

I made a game called ‘Super Luminal’ (https://play.google.com/store/apps/details?id=com.olivier_mouren.super_luminal&hl=fr) and I have out of memory issue (lot of user report me the error, friends too).

I tried the largeHeap option but without sucess : my game crash at the startup (when I preload all my image files one per one) on low-end devices. In fact, my friend have this problem with his Xperia Go and users from the Google Play too with, for exemple, Galaxy S2.

Here the report from Google Play :

java.lang.RuntimeException: java.lang.OutOfMemoryError Java Stack Trace: &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.NativeToJavaBridge.getBitmapAsset(NativeToJavaBridge.java:1114) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.NativeToJavaBridge.callGetBitmapAsset(NativeToJavaBridge.java:1394) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.JavaToNativeShim.nativeResize(Native Method) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.JavaToNativeShim.resize(JavaToNativeShim.java:212) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.opengl.CoronaGLSurfaceView$CoronaRenderer.onSurfaceChanged(CoronaGLSurfaceView.java:355) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1611) &nbsp;&nbsp;&nbsp;&nbsp;com.ansca.corona.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377) stack traceback: &nbsp;&nbsp;&nbsp;&nbsp;[C]: ? &nbsp;&nbsp;&nbsp;&nbsp;[C]: in function 'newImage' &nbsp;&nbsp;&nbsp;&nbsp;?: in main chunk &nbsp;&nbsp;&nbsp;&nbsp;[C]: in function 'require' &nbsp;&nbsp;&nbsp;&nbsp;?: in function \<?:982\> &nbsp;&nbsp;&nbsp;&nbsp;(tail call): ? &nbsp;&nbsp;&nbsp;&nbsp;(tail call): ? &nbsp;&nbsp;&nbsp;&nbsp;?: in main chunk

Here is my script that preload all my image file

local images = {"bullet.png", "explosion.png",...} -- Just a table with all my image file name local i=1 while(i\<=table.getn(images)) do &nbsp;&nbsp; &nbsp;local loaded\_image = display.newImage(images[i],0,0) &nbsp;&nbsp; &nbsp;loaded\_image.isVisible=false &nbsp;&nbsp; &nbsp;i=i+1 end

My game is ~8/9MB (‘old’ version on the Google Play is 13MB).

I hope you have some tips to solve this problem.

Hi @mouren.olivier,

I suggest, as a first step, that you check the texture memory being used. This can be wildly different (and much, much higher) than a compiled app size of 9 MB. Please see this guide for details on this topic (look under "Conserving Texture Memory):

http://docs.coronalabs.com/guide/basics/optimization/index.html

Best regards,

Brent Sorrentino

Indeed, after resize some images with correct size (PoT rule), I managed to make it work on a device that could not run before.

But, I think it’s very limited in memory, it goes very quickly to maximum (on low-end devices), how others developers do to make big applications with a lot of images, backgrounds and sprites in HD?

I can’t understand because now, I don’t think that I can add more levels in my game with this memory limit…

Hi @mouren,

There are various methods and tricks, but it depends on the game.

  1. Are you using dynamic image selection to display the “image set” that is suitable for the low-end device resolution? Corona can automatically pick the proper images for you, if you set up 2 or more sets of images at different sizes. This is almost necessary in app design, since you will want to show the best HD images possible on high-end devices, but the quality is not so important on small or low-end devices. Remember that images half the size (in pixels) take up 1/4th the texture memory, so this is a crucial point.

  2. Are you displaying only the images on screen when you need them, for that particular level?

  3. Can you scale some images that are “just over” a PoT value by making them the next lowest PoT value, then in Corona, scale them up like 5% to make them sized properly? In many cases, that scaling will not be noticed by the user, especially if it’s just a background or some texture that isn’t incredibly high in detail (sky, clouds, etc.).

  4. Can you re-use some images and “tint” them using “setFillColor()”? Depending on the image, you can make greyscale/white images and tint them to any color using that function.

  5. Are you trying to avoid big, full-screen textures? These take up a large amount of memory, and you may be able to achieve a similar effect by placing a solid or gradient vector rectangle down, then place smaller visual elements over top that.

Brent

Hi @mouren.olivier,

I suggest, as a first step, that you check the texture memory being used. This can be wildly different (and much, much higher) than a compiled app size of 9 MB. Please see this guide for details on this topic (look under "Conserving Texture Memory):

http://docs.coronalabs.com/guide/basics/optimization/index.html

Best regards,

Brent Sorrentino

Indeed, after resize some images with correct size (PoT rule), I managed to make it work on a device that could not run before.

But, I think it’s very limited in memory, it goes very quickly to maximum (on low-end devices), how others developers do to make big applications with a lot of images, backgrounds and sprites in HD?

I can’t understand because now, I don’t think that I can add more levels in my game with this memory limit…

Hi @mouren,

There are various methods and tricks, but it depends on the game.

  1. Are you using dynamic image selection to display the “image set” that is suitable for the low-end device resolution? Corona can automatically pick the proper images for you, if you set up 2 or more sets of images at different sizes. This is almost necessary in app design, since you will want to show the best HD images possible on high-end devices, but the quality is not so important on small or low-end devices. Remember that images half the size (in pixels) take up 1/4th the texture memory, so this is a crucial point.

  2. Are you displaying only the images on screen when you need them, for that particular level?

  3. Can you scale some images that are “just over” a PoT value by making them the next lowest PoT value, then in Corona, scale them up like 5% to make them sized properly? In many cases, that scaling will not be noticed by the user, especially if it’s just a background or some texture that isn’t incredibly high in detail (sky, clouds, etc.).

  4. Can you re-use some images and “tint” them using “setFillColor()”? Depending on the image, you can make greyscale/white images and tint them to any color using that function.

  5. Are you trying to avoid big, full-screen textures? These take up a large amount of memory, and you may be able to achieve a similar effect by placing a solid or gradient vector rectangle down, then place smaller visual elements over top that.

Brent