5
\$\begingroup\$

i have a problem with my game. It's a endless run shooter/platform made with LibGDX (Scene2d and box2D).

I do tests with LG G2, LG G3, Galaxy s4, desktop and android emulator and i have no one problem, but when i try to start my game on Galaxy s3 i have a very strange problem. The game crashes with no error in android and no error in android studio, simply crashes... i think its very strange because i'm developing it since a year and i always got wich error makes it crashes.

I think it's AssetManager fault because crashes often happens during loading or just finished loading (sometimes after 20-30 seconds of playing), so i tried to load less stuff and its work. I added one piece per time and at a certain point i always got a crash. In total my assets are 11mb... not so much i think. The biggest asset is the background, 2 pieces 1920*1080, near 2*70kb (yes, 70kb)...

i have in Android Studio monitor, cpu use 10~20% kernel and 10~20%user and 10~12mb memory

Here it is where the crash happens, i hope to solve soon... Thanks guys!

   public class ScreenSwitcher extends Game {
   private static ScreenSwitcher instance = null;

   public static AssetManager manager  = new AssetManager();

   private ScreenSwitcher(){
   }

@Override
   public void create () {
        loadTitle();
   }

   public static ScreenSwitcher getInstance(){
      if(istanza==null)
         istanza = new ScreenSwitcher();

      return istanza;
   }

   public void loadTitle(){
      manager.load("atlas/splash.png", Texture.class);
      manager.load("atlas/mainTitle.atlas", TextureAtlas.class);
      manager.load("atlas/shop.atlas", TextureAtlas.class);
      manager.load("atlas/loading.atlas", TextureAtlas.class);
      manager.load("atlas/duro.atlas", TextureAtlas.class);
      manager.load("atlas/sfondo.atlas", TextureAtlas.class);
      manager.load("atlas/nuovoRoy.atlas", TextureAtlas.class);
      manager.load("atlas/altro.atlas", TextureAtlas.class);
      manager.load("atlas/shipFlag.atlas", TextureAtlas.class);
      manager.load("atlas/collezionabili.atlas", TextureAtlas.class);
      manager.load("atlas/lucertole.atlas", TextureAtlas.class);
      manager.load("atlas/lumaca.atlas", TextureAtlas.class);
      manager.load("atlas/terreni.atlas", TextureAtlas.class);
      manager.load("atlas/decorazione.atlas", TextureAtlas.class);
      manager.load("atlas/piatte.atlas", TextureAtlas.class);
      manager.load("atlas/nuvolette.atlas", TextureAtlas.class);
      manager.load("atlas/pezzi.atlas", TextureAtlas.class);
      manager.load("atlas/pulsanti.atlas", TextureAtlas.class);
      manager.load("atlas/ragnetto.atlas", TextureAtlas.class);
      manager.load("atlas/scatole.atlas", TextureAtlas.class);
      manager.load("atlas/volante.atlas", TextureAtlas.class);
      manager.load("atlas/volanteBonus.atlas", TextureAtlas.class);
      manager.load("atlas/volantePorta.atlas", TextureAtlas.class);
      manager.load("atlas/trappole.atlas", TextureAtlas.class);
      manager.load("atlas/esplosione.atlas", TextureAtlas.class);
      manager.load("atlas/jumpfall.atlas", TextureAtlas.class);
      manager.finishLoading();

      setScreen(new GameScreen());
   }
\$\endgroup\$
  • \$\begingroup\$ You won't always be able to detect the reason for crashing from the program. Validation is usually up to the programmer. I don't know much about LibGDX, but you might wish to validate your data before you use it. \$\endgroup\$ – moonshineTheleocat May 15 '16 at 7:21
  • \$\begingroup\$ Also consider that the s3 has less RAM than the other phones. Probably that is the cause. It is getting out of RAM during loading of your game. \$\endgroup\$ – rlam12 May 15 '16 at 14:34
  • \$\begingroup\$ total memory usage is 10-12mb! \$\endgroup\$ – flagDiZero May 15 '16 at 14:57
  • 1
    \$\begingroup\$ This isn't exactly question related but you don't need to have a static instance of your Game. You can use Gdx.app.getApplicationListener() instead to get the instance. \$\endgroup\$ – Charanor Nov 3 '16 at 12:46
1
\$\begingroup\$

When you use the Assetmanager , you should dispose the loaded textures after the use. This can be done by implementing the Disposable and AssetErrorListener interfaces .This way you get the method called dispose() to dispose the Assetmanager. Here is a quick example:

 public class gh implements Disposable,AssetErrorListener {

@Override
public void error(AssetDescriptor asset, Throwable throwable) {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {


  //so you can release the AssetManager
    AssetManager.dispose;
    // TODO Auto-generated method stub

}

   }
\$\endgroup\$
  • \$\begingroup\$ Please use the 'edit' feature at the bottom of the post to edit your post when you need to improve it. You can edit your own posts as much as you need (as long as it makes sense). So there is no need to double post :) \$\endgroup\$ – Vaillancourt May 20 '16 at 20:29
  • \$\begingroup\$ no man, the error happens before any call to dispose method \$\endgroup\$ – flagDiZero May 21 '16 at 8:15
0
\$\begingroup\$

In my experience, Box2D is a little fussy about dealing with things such as line lengths that are shorter than a hard-coded lower limit. I don't recall the lower limits, but you can find the checks in the Box2D source. Box2D will throw an exception which is unable to cross the JNI boundary and brings the whole process down with no explanation. Maybe add some of your own checks at points where you make calls to Box2D to make sure data is within the limits it will accept?

\$\endgroup\$
  • \$\begingroup\$ Sounds like you've been running into Box2D's use of the C/C++ assert macro. The thing with asserts though is they're meant for debugging use and in fact are disabled by compiling code with NDEBUG defined. But the Java implementation/wrapper of Box2D chooses not to do this. If libgdx used Box2D built with NDEBUG then instead of crashes, returned values from creator functions would need to be checked. And these should be checked anyway. So in a sense I think libgdx deserves some responsibility for the fussiness too. \$\endgroup\$ – Louis Langholtz Jun 3 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.