Jump to content

  • Log In with Google      Sign In   
  • Create Account

EasyCoder

Member Since 19 Aug 2011
Offline Last Active Mar 02 2013 10:09 AM

#4908500 Problem with loading bitmaps into Android Application

Posted by EasyCoder on 01 February 2012 - 03:50 PM

Thanks Fiallen, for trying to help me with this. You seem to know what are you talking about (as opposed to Antheus above, who just googles and stabs in the dark) Posted Image

This is my first game in Android and I already thought I have a fully working game engine, which I was designing by myself from scratch, and can concentrate on the level design, when this setback with textures, which sent me right back to the square one Posted Image

Are you using LogCat to track the exact nature of the exception and get the stack trace?


Yeah, sure I use that from beginning, it's extremely useful, and now when you mentioned it, I've looked into it really in detail again, but still cannot figure out what I am doing wrong.

When I was seeing our OOM exception LogCat was able to tell me the resource Id i was loading and how much memory it was trying to allocate (With the stack trace it was more than enough to diagnose the cause)? You are more than likely already aware that the .png's are small in their compressed state but once loaded into memory they are uncompressed bitmaps so will consume (width x height x bytesperpixel) bytes. It is also extremely easy to leak memory in Android but I don't believe this is your issue from your original post.


This is where I am really getting confused. I was originally allocating well less than width x height x 4, and it still worked (see first log) and when I increased that significantly, it seemed to make no difference in amount of allocated memory. As you will see from log there is always this magical number 1925136 bytes floating around, even I increase allocation by thousandfold.

For clarity, I am posting 2 logs in following two posts.

1st log is where the game starts fine, about 50 or so textures ranging in size from 80x80 to 1280x752 load just fine and everything works great. This works whether I put to allocation ridiculously small numbers, or their thousedfold values (width * height * 4 does not work, that crashes immediately, but I put there anything from 12 * 4 to width * 4 and it did not seem to make an iota of difference - all textures loaded and game ran). As you can see though there is something strange going on there - it seems like Android is running out of puff there, having 1-2-3% of memory free, then suddenly reclaims up to 71%!

2nd log is the same situation, I did not change memory allocation, only added one more object loading one more 1280x752 texture. That is where it crashes.

I figured that I just can null some texture objects/classes and reinstate them later when I need them, but I cannot figure out how to do it either. See:

http://www.gamedev.n...__fromsearch__1

Either Android/Java is extremely difficult environment, or I am a lousy programmer Posted Image

I am stuck with this problem now about 2 weeks and will be very grateful if you could show me the way out of this mess.


#4908058 Problem with loading bitmaps into Android Application

Posted by EasyCoder on 31 January 2012 - 10:29 AM

Android applications are limited to 16MB/24MB of RAM.


Obviously you weren't reading my question properly. There is 48MB memory btw in Android 3.0, and some 70% are still free before it all goes balls up!


PARTNERS