Android limitations

All topics about ZGameEditor goes here.

Moderator: Moderators

Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Android limitations

Post by Imerion »

I have made a few games which have all compiled and worked well for/on Android. My latest game, however, crashes immediately upon start on the same device the others worked on. The only difference I can see is that this new project is much larger uncompressed (about 360 MB, due to loads of full-screen pictures - it's sort of an adventure game.) Could that be the problem? My device should have over 1 GB of free memory, so I doubt it runs out. And some apps, like Hearthstone, is over 4 GB.

If the size is not the problem, are there any other known problems with running ZGE games on Android? I doubt I'm using anything special; the game is 2D and quite simple code-wise...
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: Android limitations

Post by Rado1 »

Hi Imerion, I just tried to regenerate old Android projects with latest ZGE and they work fine. Could you please send me the APK for analysis? Or you can try logcat (from Android Device Monitor) by yourself to see what's the problem.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

Hi! Thanks for your offer Rado1! I haven't used logcat, but was curious if there was a way to see output in Android. I will look into it. If you want to give it a try, I have included an apk here. That would be a big help! It's a beta, so some things will change before final release, but the game should run and play fine as is.
Attachments
Sweatpants Simon-release.apk
(8.25 MiB) Downloaded 398 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: Android limitations

Post by Rado1 »

Tests on Google Nexus 10 shown that the reason why the application crashes is that it goes out of memory. After several message like:

Code: Select all

04-29 07:46:14.312: E/art(31584): Throwing OutOfMemoryError "Failed to allocate a 362527386 byte allocation with 5065082 free bytes and 184MB until OOM"
it gives definite:

Code: Select all

04-29 07:46:14.355: E/AndroidRuntime(31584): java.lang.OutOfMemoryError: Failed to allocate a 362527386 byte allocation with 5065060 free bytes and 184MB until OOM
So you probably try to load large resources to memory... I suggest to reduce their size, if possible. In general, this is not problem of Android this is problem of usual Android devices with limited memory.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

Ok, so it was the memory. :( I'll see what I can do to reduce it. Thanks a lot for your help!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Android limitations

Post by Kjell »

Hi Imerion,
Imerion wrote:I'll see what I can do to reduce it.
Not to be a "debbie downer", but as long as ZGameEditor doesn't store imported assets ( bitmap / mesh / sample ) as resources when building a Android APK, it's going to be difficult to circumvent this problem for games that use lots of data*

*Aside from the fact that there's no built-in mechanic to unload / recycle OpenGL textures.

K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Android limitations

Post by VilleK »

What is the resolution of those images? And approximately how many images are included in the project? The limitation here is that ZGE requires all images to fit in RAM, uncompressed.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

There are quite many, most of which are around 512x512 to 1366x768. It's not the most effiecient way of doing things. And I realize this type of game isn't really what ZGE is for. Uncompressed, the data amounts to 360 MB, images, sound and everything included.

What I'm thinking about doing is reducing the resolution of each, then scale them up. It won't look as crisp, but on a tiny mobile screen that might not matter. It's currently optimized for my laptops 1366x768.
zondarg
Posts: 13
Joined: Fri Jan 01, 2016 12:17 pm

Re: Android limitations

Post by zondarg »

VilleK wrote:What is the resolution of those images? And approximately how many images are included in the project? The limitation here is that ZGE requires all images to fit in RAM, uncompressed.
Does "uncompressed" in this context mean always 24bit or even 32bit per Pixel, or is there a way to use indexed or reduced bit (5/6/5 or less bits) color?

..just curious, thinking forward to the next graphics-heavy project with ZGE... :D
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Android limitations

Post by VilleK »

Uncompressed 24 or 32 bit pre pixel, depending on if alpha channel is included. The problem here is probably also that ZGE on Android loads a copy of the whole resource to memory before reading from it so memory usage on startup will be twice the resource size. I can try to get memory usage down if this is a problem. One option could be to let ZGE automatically scale down imported textures when building for Android.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

Automatic scaling down would be a very useful option! Especially if you can adjust how much, so there could be a phone setting which does more scaling down than the tablet setting. Any other optimizations in this area would of course be useful too.

Now that you mention it, I could remove the alpha channel for many of those images. And in some cases I could use black for transparency. That could probably reduce memory usage a bit. If you think it will help, I'll try it!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Android limitations

Post by Kjell »

Hej Ville,
VilleK wrote:The problem here is probably also that ZGE on Android loads a copy of the whole resource to memory before reading from it so memory usage on startup will be twice the resource size.
Doesn't that mean that it'll be in memory ( CPU & GPU share RAM on mobile ) three times once the OpenGL texture has been created ( using lazy initialization )?

Anyway, some bullet points quoted from the iOS documentation ..
  • After loading an image into an OpenGL ES texture, free the original image.
  • Allocate a depth buffer only when your app requires it.
  • If your app does not need all of its resources at once, load only a subset of the items. For example, a game might be divided into levels; each loads a subset of the total resources that fits within a more strict resource limit.
Neither of which are ( easily ) doable in ZGE at the moment.

K
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

I have tried to reduce size a bit, to at least help the problem, but it didn't amount to much. Mainly because I thought removing the alpha channel from my png:s would reduce the uncompressed size (going from 32 bit to 24 bit), but that didn't seemed to help at all. Shouldn't it?

The only thing I can think of now, besides scaling things down, is to replace my png images with jpg ones. Or would the uncompressed size still be the same?

Also, about getting memory usage down: If it would be possible to have the resources only read into memory twice at startup, instead of three times as suggested by Kjell, my game would probably run on most modern devices.

However, another idea would be to add a function that, when building for Android, converts all png to jpg at a choosable compression level. Perhaps that would help? :)
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Android limitations

Post by VilleK »

I think that when it fails to allocate 360mb it is the whole uncompressed data file that is the problem (i.e. the size of zzdc.dat). If you change to Jpg compression then this file will be much smaller so it might solve the problem. And it would indeed be helpful if this could be done automatically when building for Android but unfortunately I don't have the time to make a feature like that at the moment, sorry :).
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Android limitations

Post by Imerion »

Thanks for your suggestions! The game now runs, but not on my devices. :)

I have reduced the games size from 360 MB to 132 MB. I've been converting graphics to JPG, reducing size of images as well as cutting a few things that weren't necessary. But I still can't get the game to run on my phones. Rado1 got it working on a Nexus10 with 2 GB of ram. My devices only have 1.5 GB ram. Could that be the difference?

Could the fact that the game runs in a slightly higher resolution than what the phones have be a problem? I thought it would scale up/down automatically.

Could it be anything else? My previous Android-compiled projects have worked fine on those devices.
Post Reply