Question

I've loaded all of my images successfully in the past and I'm using OpenGL ES 2.0 so the images don't need to be powers of two (I have several loaded successfully that aren't).

The code in question is this:

Line 96: splashSheet = new Texture(Gdx.files.internal("test.png"));

This is my error message:

    Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: test.png
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: test.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:175)
    at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
    at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
    at com.panini.game.GameScreen.show(GameScreen.java:96)
    at com.badlogic.gdx.Game.setScreen(Game.java:59)
    at com.panini.game.Splash.render(Splash.java:29)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:190)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)
Caused by: java.io.IOException: couldn't load pixmap
    at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)
    ... 11 more

Here's what makes this an interesting problem. I can load this file, but I can't load this one. The former is basically just a cropped screenshot of the one I want to use. The second image I've provided (which doesn't work) is the original. It is called splashSprites.png but I've tried renaming it to test.png and referring to it properly but it still doesn't work, so I know it's definitely not a naming issue or anything. If I put both files in the assets or bin directory named test1.png and test2.png respectively, then the code works if I ask to load test1.png but not if I ask to load test2.png, so it's not that I'm putting the files in the wrong place either. Those two seemed to be the most likely candidates but I've ruled them out.

I tried other things like re-exporting the first image and such but it never worked (what did work was taking a screenshot, which is why I'm here). My guess is that it may have something to do with the alpha in one of the images (because that's really the only thing different from the two - one has alpha the other doesn't) but that's unlikely since I was able to load some other textures which did have alpha. I'm really stumped.

Thanks in advance.

Was it helpful?

Solution

I found the answer. Apparently LibGDX does not support 16-bit pngs (is this right?) because after converting my spritesheet to 8-bit depth using Preview on OS X, I found the problem vanished.

Thanks to P.T. for the advice to upgrade LibGDX because that's how I got the following error message:

Caused by: java.io.IOException: couldn't load pixmap 8bit only

OTHER TIPS

Run pngcrush on the image to get it into a more common PNG format.

Is this screenshot generated with the libGDX forum's screenshot code? I used that too, and had problems with the resulting PNGs being enormous, and I believe I had some problems loading/editing them, too. Anyway pngcrush fixed the problem for me.

The pngcheck tool might be able to isolate what is different between the two images you have.

Poking at the libGDX source, I see this recent (11 days ago) change to the libGDX image loader: https://github.com/libgdx/libgdx/commit/4fac29aef94e3afafdd47d71e60faf256fa171b0 (it looks like the IOException should include more information about what really went wrong), so you might try running against the libGDX nightlies?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top