I'm working on a game for Android using Android Studio with LibGDX in Java. I recently found a weird problem when closing and reopening the game. When I first open the game, it works fine. If I click the QUIT button and close the app, the asset manager disposes. When I reopen the game, some of the atlas regions are shown as black rectangles in the same size of the region. I noticed that it happens only when I call assets manager's dispose method. If I remove it, the problem doesn't appear. It's funny, but the game seems to work fine when not calling that method but I read that it is recommended to dispose it. This is my AssetsManager class:
public final class AssetManagerWrapper extends AssetManager { ArrayMap<String, FileHandle> configs = new ArrayMap<String, FileHandle>(); public Texture lightTexture; public Texture alarmTexture; public TextureAtlas particlesAtlas; public final void loadGFX() { FileHandle dirHandle; dirHandle = Gdx.files.internal(Rules.System.GFX.GFX_FOLDER_NAME); FileHandle subDirHandle; for (FileHandle dir : dirHandle.list()) { subDirHandle = Gdx.files.internal(dir.path()); if (dir.name().equalsIgnoreCase(AssetsPaths.Gfx.Sheets.SHEETS_FOLDER_NAME)) { for (FileHandle file : subDirHandle.list()) { if (file.extension().equalsIgnoreCase(Rules.System.GFX.SHEETS_DATA_EXTENSION)) { load(file.path(), TextureAtlas.class); } } } else { for (FileHandle file : subDirHandle.list()) { load(file.path(), Texture.class); } } } } public final void loadSounds() { FileHandle dirHandle; dirHandle = Gdx.files.internal(Rules.System.SFX.SFX_FOLDER_NAME); FileHandle subDirHandle; for (FileHandle dir : dirHandle.list()) { subDirHandle = Gdx.files.internal(dir.path()); if (dir.name().equalsIgnoreCase(Rules.System.SFX.SOUNDS_FOLDER_NAME)) { for (FileHandle file : subDirHandle.list()) { if (file.extension().equalsIgnoreCase(Rules.System.SFX.SOUNDS_DATA_EXTENSION)) { load(file.path(), Sound.class); } } } } } public void loadParticlesConfigs() { FileHandle dirHandle; dirHandle = Gdx.files.internal(AssetsPaths.Configs.CONFIGS_FOLDER_NAME + '/' + AssetsPaths.Configs.PARTICLE_CONFIGS_FOLDER_NAME); for (FileHandle file : dirHandle.list()) { if (file.extension().equalsIgnoreCase(Rules.System.GFX.PARTICLE_CONFIGS_DATA_EXTENSION)) { configs.put(file.nameWithoutExtension(), file); } } } public final void loadMusic() { FileHandle dirHandle; dirHandle = Gdx.files.internal(Rules.System.SFX.SFX_FOLDER_NAME); FileHandle subDirHandle; for (FileHandle dir : dirHandle.list()) { subDirHandle = Gdx.files.internal(dir.path()); if (dir.name().equalsIgnoreCase(Rules.System.SFX.MUSIC_FOLDER_NAME)) { for (FileHandle file : subDirHandle.list()) { if (file.extension().equalsIgnoreCase(Rules.System.SFX.MUSIC_DATA_EXTENSION)) { load(file.path(), Music.class); } } } } } public void loadData() { loadGFX(); loadSounds(); loadMusic(); loadParticlesConfigs(); finishLoading(); } @Override public void finishLoading() { super.finishLoading(); lightTexture = get(AssetsPaths.Gfx.Other.LIGHT); alarmTexture = get(AssetsPaths.Gfx.Menu.ALARM); particlesAtlas = get(AssetsPaths.Gfx.Sheets.Misc.PARTICLES_DATA_FILE); } public ArrayMap<String, FileHandle> getConfigs() { return configs; } } The life-cycle (Main class which implements Application Listener):
@Override public void create() { assetsManager = new AssetManagerWrapper(); assetsManager.loadData(); soundPlayer = new SoundPlayer(this); Gdx.input.setCatchBackKey(true); goToMenu(); } @Override public void resume() { assetsManager.finishLoading(); } @Override public void dispose() { assetsManager.dispose(); //For some reason this creates the black rectangles bug. soundPlayer.dispose(); if (warScreen != null) { warScreen.dispose(); } menuScreen.dispose(); } Does anybody have any idea what could cause it? Is that ok that I just remove the call to that method? Thanks in advance.
AssetManagerWrapperclass? Who callsloadDataand when, and who callsdisposeand when? \$\endgroup\$