Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

This is one more post about the issues we had while releasing the game for Android.

All along the development of this project, we planned to launch the game both for desktop and for Android, and it was working great on a phone and a tablet we were using for testing. Except that after the last weekend rush, when we added lots of new contents (and assets), the game started to not render correctly on the phone (Samsung Galaxy Nexus).

There were lots of texture problems, like texture missing, unreadable text...


Also I found this error which was continuously spamming the log while the game was running:

E/IMGSRV ( 2198): :0: PVRSRVAllocDeviceMem: Error 1 returned
E/IMGSRV ( 2198): :0: PVRSRVAllocDeviceMem: Error 1 returned
E/IMGSRV ( 2198): :0: PVRSRVAllocDeviceMem: Error 1 returned

...

After some searches, I found it was a failure from the GPU memory, which probably means the phone was out of memory!
There can be two reasons for this (at least): texture are too big for the phone's GPU memory capacity, or memory leak.

Actually it was both!

1) I fixed one bug with a texture which was never released when exiting the game. This is no big deal on desktop, but it seems to cause on Android a lot of garbage in memory after few times lauching the app.

2) We were loading exactly the same assets for both desktop and Android. They needed to be big enough to look great on a large display for desktop and high-resolution tablets, but it was too much memory for a phone. And it was useless, since it will anyway be reduced a lot during rendering and mipmaps corresponding to screen size would be applied!
I added some code while loading texture to check if the screen was a smaller size than expected, and in this case textures were reduced before being stocked in memory.
I used for that a temporary pixmap to load the real size texture, and draw it inside another pixmap with reduced size, and then this pixmap data could be saved to a texture. Here is the final code for texture loading:

     FileHandle assetFile;
     Pixmap pix = new Pixmap(assetFile);

     final float desiredWidth = 1280.f; // or whatever is the default width on desktop
     float scale = (float)Gdx.graphics.getWidth() / desiredWidth;

     if (scale < 0.75f) // no need to do anything if the size difference is not too bad...
     {
          int realWidth = pix.getWidth();
          int realHeight = pix.getHeight();

          int scaledWidth = (int)((float)realWidth * scale);
          int scaledHeight = (int)((float)realHeight * scale);

          Pixmap scaledPix = new Pixmap(
               realWidth, realHeight,
               pix.getFormat());
                
          Pixmap.setFilter(Pixmap.Filter.BiLinear);
                
          scaledPix.drawPixmap(scaledPix,
               0, 0, realWidth, realHeight,
               0, 0, scaledWidth, scaledHeight);

          pix.dispose();
          pix = scaledPix;
     }

     final boolean useMipmap = true;

     Texture texture = new Texture(pix, useMipmap);

     pix.dispose();

     if (useMipmap)
     {
          texture.setFilter(
               Texture.TextureFilter.MipMapLinearLinear,
               Texture.TextureFilter.Linear);
     }


After that (and restarting the phone to be sure to remove all garbage from memory), no texture issues showed up anymore!