Saturday, November 20, 2010

Blue Skies v1.15

  - Bug Fix: Moon image not showing up on some handsets
  - Update: Stars twinkle more
  - Update: Balloons light better

The moon thing is actually a bit odd, let's discuss that.  Basically, if you dig back in the archives far enough, you'll find a post about Android incorrectly premultiplying PNG files.  What I did to work around that was implement a loader for TGA images, which generally works well.  As a bonus I got support in for greyscale luminance textures that way as well, which has definitely saved some memory here and there.

Now, since TGA isn't a native Android image format, the program that builds the APK package compresses it to save space, like when you're making a ZIP file.  The standard formats of PNG and JPG don't get this compression, since they're compressed already and it's a waste.

Once you have a compressed file in your APK, what happens later on is you open the file and attempt to read it.  The system transparently decompresses it into memory to allow this, so you yourself don't need to deal with the compression at all.  You read the file and close it, the systems throws away the temporary decompressed version, and all is well.

The wrinkle is that this temporary buffer it puts things into has a size limit, of around 512k.  If the file in question is bigger than that, it'll just fail to open and you're out of luck.  That's what happened here, the uncompressed TGA file for the moon was bigger than 512k, so the file didn't open, so my TextureManager class just returned an empty white image.  Now the question is, how did I manage to miss this?  Don't I ever test anything?

Well, that's the trick.  Some of the manufacturers raise this limit.  I know Motorola and HTC do -- to what, I'm not sure.  I've run into this before, and I know to pay attention to it, but since I was testing primarily on an HTC Incredible, it worked just fine and I forgot to double-check it.  It worked on a Droid 2 as well.  It does not, however, work on something like a G2 or a Nexus One that's running stock Android.

So what can you do to work around this?  Annoyingly, the Eclipse ADK doesn't support any way to tell a file to store uncompressed.  If you write an ANT script or something you can do that, but the Eclipse build process won't let you.  However, if you want to work around THAT, you can change the filename extension to something like JPG, and the Eclipse build process will automatically skip compressing it, and you can make your file as big as you like.  I mean, hey, the Android resource process doesn't use extensions anyway, right?

So, to summarize:  Careful about non-native file sizes in your package files, if it's larger than half a meg you might run into trouble.

EDIT:  It looks like the 'assets' folder can be used for the purpose of non-compressed files, which somehow or other I missed the last time I was researching this.  I'll have to try this next go-round.

5 comments:

  1. I'm having trouble running Galactic Core and Asteroid Belt. (I haven't tried any others yet.) When I select the wallpaper from the menu, it just says "loading wallpaper". After opening/closing the settings, I am able to set it as my wallpaper and go back to my home screen, but it doesn't run and it just restores my previous wallpaper. I'm running Froyo on a Droid Eris.

    ReplyDelete
  2. How to get full version?
    bj_jin2003@yahoo.com

    ReplyDelete
  3. Hello,

    how do i get full version?
    foxeoh@hotmail.com

    ReplyDelete
  4. please help ; android market is not available in my country, yet ; how can i obtain/pay for the full versions of this amazing live wallpapers that u create ?

    ReplyDelete