brahamlir / andengine

Automatically exported from code.google.com/p/andengine
0 stars 0 forks source link

BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset can not find bitmap files when file has underscores in the name #53

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Try to load a bitmap file with underscore _ in the name:

    @Override
    public void onLoadResources() {

        this.mTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

        // Create the ball:
        this.mBallTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mTexture, this, "gfx/ui_ball.png", 0, 0, 2, 4);

        // Create the player:
        this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mTexture, this, "gfx/uiPlayer.png", 128, 0, 2, 4);

        this.mEngine.getTextureManager().loadTexture(this.mTexture);
    }

ui_ball.png triggers the following error:

09-04 17:20:55.205: ERROR/AndEngine(647): Failed loading Bitmap in 
AssetBitmapTextureAtlasSource. AssetPath: gfx/ui_ball.png
09-04 17:20:55.205: ERROR/AndEngine(647): java.io.FileNotFoundException: 
gfx/ui_ball.png
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
android.content.res.AssetManager.openAsset(Native Method)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
android.content.res.AssetManager.open(AssetManager.java:314)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
android.content.res.AssetManager.open(AssetManager.java:288)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasS
ource.onLoadBitmap(AssetBitmapTextureAtlasSource.java:105)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTexture
ToHardware(BitmapTextureAtlas.java:156)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.Texture.loadToHardware(Texture.java:116)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.TextureManager.updateTextures(TextureManager
.java:146)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:503)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSu
rfaceView.java:154)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.guardedRun(GLSurfaceView
.java:617)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.run(GLSurfaceView.java:5
49)
09-04 17:20:55.205: ERROR/AndEngine(647): Error loading: 
AssetBitmapTextureAtlasSource(gfx/ui_ball.png)
09-04 17:20:55.205: ERROR/AndEngine(647): java.lang.IllegalArgumentException: 
AssetBitmapTextureAtlasSource: AssetBitmapTextureAtlasSource(gfx/ui_ball.png) 
returned a null Bitmap.
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas.writeTexture
ToHardware(BitmapTextureAtlas.java:159)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.Texture.loadToHardware(Texture.java:116)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.texture.TextureManager.updateTextures(TextureManager
.java:146)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.engine.Engine.onDrawFrame(Engine.java:503)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.RenderSurfaceView$Renderer.onDrawFrame(RenderSu
rfaceView.java:154)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.guardedRun(GLSurfaceView
.java:617)
09-04 17:20:55.205: ERROR/AndEngine(647):     at 
org.anddev.andengine.opengl.view.GLSurfaceView$GLThread.run(GLSurfaceView.java:5
49)

When file is renamed it works fine.
I'm using latest version from the trunk

Original issue reported on code.google.com by pflikwe...@gmail.com on 4 Sep 2011 at 3:29

GoogleCodeExporter commented 9 years ago
when i add files and build a sample, i got the same problem. But when i rename 
file to other name and revert it back, than all works fine. i think its not 
appengine source problem, it is something with eclipse resources update or 
something else. i'm newbie in android programming so maybe i'm wrong.

Original comment by skyg...@gmail.com on 15 Nov 2011 at 8:17

GoogleCodeExporter commented 9 years ago
Hi all.
I think that the reason of the error has been caused by the code which opening 
asset file.
Please look code below.

http://code.google.com/p/andengine/source/browse/src/org/anddev/andengine/opengl
/texture/atlas/bitmap/source/AssetBitmapTextureAtlasSource.java?r=ea4ff643a0e588
57e92738a6e5449b6a362190cd#55
54: try {
  :-        in = pContext.getAssets().open(pAssetPath);
  :+        in = pContext.getAssets().open(BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetPath);
56:     BitmapFactory.decodeStream(in, null, decodeOptions);

The origin code has not considered behaviour which does not contain the 
assetBasePath.

Original comment by oasynnoum@gmail.com on 3 Apr 2012 at 11:22