Aqvin
Aqvin

Reputation: 85

Libgdx AssetManager not loading resources on resume

I am using Libgdx assetmanager to load UI assets. It works perfectly fine until I restart the application(Android). Here is what happens:

  1. I start my game: It runs fine
  2. I close the application using Gdx.app.exit() (No errors)
  3. Now when I press on the app icon to open it: crashed!

Error: com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: data/GUI/packed/gui.atlas

I tried finishloading() No luck! I tried using finishloadingasset("data/GUI/packed/gui.atlas") this blocks forever! Added assetmanager.dispose() also clear before exit. No luck!

After it is crashed, if i try to open it again it works just fine!

Please advice! Thanks

Upvotes: 0

Views: 369

Answers (1)

Tenfour04
Tenfour04

Reputation: 93581

Closing an Activity in Android does not automatically clear your static references. Do not hold any static references to any OpenGL-related objects such as AssetManagers, Textures, ShaderPrograms, SpriteBatches, etc., or you risk Android reopening your game without knowing how (or that it needs) to reload them.

There might be ways around this by clearing your static references in your Activity's onCreate method, but it's safer/easier to avoid static references altogether.

Upvotes: 2

Related Questions