useruseruser
useruseruser

Reputation: 73

Asset Manager load pixmap outof mem Libgdx Java

I am creating a libgdx game, and it worked fine, loaded all of the assets perfectly etc. However I then tried to implement libgdx's Asset Manager' to add an active loading screen etc. But after doing this my game would take ages to load on desktop, keeping a black screen, almost crashing then finally crash and on my assets I kept receiving the error or similar:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load 
    file: data/startBackground.png
        at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
        at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
        at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
        at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
        at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
        at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
        at com.MKgames.game1.screen.MainMenuScreen.show(MainMenuScreen.java:98)
        at com.badlogic.gdx.Game.setScreen(Game.java:61)
        at com.MKgames.Game1.render(Game1.java:41)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:206)
        at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
    Caused by: java.io.IOException: couldn't load pixmap outofmem
        at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
        at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)
        ... 10 more

I then tried deleting my assets class and the same thing keeps happening.

data/startBackground.png is a 1920*1080 .png image.

I have a feeling it may be an issue more with the running it on the computer opposed to the game itself?

Here is how the asset is loaded normally without asset manager (this used to work before i tried to implement asset manager but now it does not once i removed asset manager):

public void show() {
        Texture backgroundTexture = new Texture(Gdx.files.internal("data/startBackground.png"));
        background =  new Sprite (backgroundTexture);

}

Here's how I loaded this assets using asset manager:

public class Game1 extends Game{
public void render() {
        if(Assets.update()){
            this.setScreen(new MainMenuScreen(this));
        }
    }
}

...

public class Assets {

    public static AssetManager manager = new AssetManager();

    public static void queueLoading() {
        (..)
        manager.load("data/startBackground.png",Texture.class);
        (..)
    }
    public static boolean update() {
        return manager.update();
    }
}

Upvotes: 1

Views: 568

Answers (1)

Juan Javier Cassani
Juan Javier Cassani

Reputation: 460

Game1 render method is called every frame, so you are creating a new screen on each frame, and screen is creating a new texture instance in every show call, you finally get out of memory.

Also, don't forget to add

super.render();

In your game class render method. Otherwise, current screen's render() wont be called

Upvotes: 1

Related Questions