ClassCastException on loading images in AWTLoader, wrong Key assumed

in AWTLoader.java

[java]public Object load(AssetInfo info) throws IOException {

if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){

InputStream in = info.openStream();

boolean flip = ((TextureKey) info.getKey()).isFlipY(); // <- exception!

Image img = load(in, flip);

in.close();

return img;

}

return null;

}[/java]



When trying to load a simple gif, i get a ClassCastException “AssetKey cannot be cast to TextureKey”.

Shouldnt one first test if getKey returns something that is a TextureKey?

When the AWTLoader is used its a texture. If you want to load raw gif data you have to remove the gif extension from the texture loader.

and you really think just inserting my code would’nt be the far more obvious and better way? Its after all just bad style assuming an untested classcast to succeed if you’re not damn shure it is the correct class.

How do you manage to make this happen in the first place? You just use a vanilla AssetKey? As @Momoko_Fan pointed out thats incorrect when you load a texture and would result in problems later. (Why what you load is a texture I already explained)

I just did

[java]Image img = (Image) loadAsset("foo/bar.gif");[/java]

expecting assetmanager to be able to load an image (no, it is not a texture)

my engine will compile some of these loaded images into textures others into swing-buttons and some into both. but first of all, i need to load an image. Assetmanager should be able to do that. in fact, it is, it just has to accept at the pointed out line in the src of AWTLoader, that it perhaps doesnt got a TextureKey. And removing gif-extension from the awt-loader would stop him beeing able to load gifs – not what i want.

assetManager.loadTexture(“foo/bar.gif”).getImage()

Hm… normally only TextureKeys should arrive there… But I guess you’re right, a simple texture should be loadable by a generic AssetKey with just a name… If you come to fix this before us, please post patches instead of the whole code, you can create one in jMP by selecting the file and going to Team->Export Diff Patch

i dont use JMP for code. i tested netbeans and after beeing astonished how wired that IDE is (it even looks ugly) i returned to eclipse. To be honest, i currently dont use JMP at all, because im still in the coding phase and all grafix is either placeholder or already done but not included, because it is not yet needed.

rhavin said:
i dont use JMP for code. i tested netbeans and after beeing astonished how wired that IDE is (it even looks ugly) i returned to eclipse.

Aha. So please post patches :P

[java] boolean flip = false;

AssetKey k = info.getKey();

if (k instanceof TextureKey)

flip = ((TextureKey)k).isFlipY();[/java]



…?

Ok, next time i’ll take that road. For now, i have a two gigs in front of me…

The requirement is absolute, if its not held, then some undesired bugs will happen. Textures should only be loaded via TextureKeys, if the exception is not clear enough then we can improve it, like “Textures should only be loaded via TextureKeys” …

I dont load a texture, i load a simple gif.

like this:



[java]Image img = (Image) loadAsset("foo/bar.gif");[/java]



AssetManager should be able to handle that.

yes, a way of buying a screw is buying a train and remove a screw;-)

Well as I said you can register .gif with your own loader, you just wont be able to load gif textures then anymore (which nobody does anyway).

jME3 is a 3D game engine. When you load an image file through jME, it is implied that you are going to use it as a texture.



If you wish to use the data loaded for other purposes, please use the getImage() method as normen indicated.