TMX: Handling of TileID==0 leads to NullPointerException

  ... in the unlikely case you discovered a bug, post it here.

TMX: Handling of TileID==0 leads to NullPointerException

Postby .joe » Sun Feb 12, 2012 8:21 pm

Hi,

in TMXLayer.addTileByGlobalTileID(...) TileId==0 is handled this way:
Code: Select all
if (pGlobalTileID == 0) {
   tmxTileTextureRegion = null;
} else {
   tmxTileTextureRegion = tmxTiledMap.getTextureRegionFromGlobalTileID(pGlobalTileID);
}
//...
if (this.mTexture == null) {
   this.mTexture = tmxTileTextureRegion.getTexture();
   super.initBlendFunction(this.mTexture);
} else {
   if (this.mTexture != tmxTileTextureRegion.getTexture()) {
      throw new AndEngineRuntimeException("All TMXTiles in a TMXLayer need to be in the same TMXTileSet.");
   }
}


The problematic case is:
pGlobalTileID == 0 and this.mTexture == null
This causes a NullPointerException at the call tmxTileTextureRegion.getTexture() because tmxTileTextureRegion is previously set to null.

I was looking around to find a solution to this case, but i did'nt found one yet. As far as I can see a texture is always required. Maybe a transparent default texture can be a solution for tiles not having any tileset.
.joe
 
Posts: 4
Joined: Sun Feb 12, 2012 8:05 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby Niffy » Fri Feb 24, 2012 6:40 pm

Go to the extension on github, in its issue section you should see one or two solutions to fix it.
Niffy
 
Posts: 284
Joined: Sat Sep 17, 2011 8:39 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby Harti79 » Sun Mar 04, 2012 11:48 am

Have you found a solution for this problem?
Harti79
 
Posts: 90
Joined: Wed Dec 21, 2011 5:48 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby .joe » Sun Mar 04, 2012 11:54 am

I have tried the patch by Loffe (https://github.com/nicolasgramlich/AndE ... ion/pull/1) but now i have a NullPointerException in SpriteBatch.preDraw instead.

So, no i don't have a solution yet.
.joe
 
Posts: 4
Joined: Sun Feb 12, 2012 8:05 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby .joe » Sun Mar 04, 2012 1:17 pm

Ok the other error had nothing to do with the reported above. The patch of Loffe fixes the problem.

Had another problem that i found now (after many hours). A change in the API that is really hard to find. For everyone who has a black screen after upgrading to gles2 might want to have a lock at BoundCamera.setBounds. Arguments have exchanged so you might set your camera to senseless values after the upgrade.
.joe
 
Posts: 4
Joined: Sun Feb 12, 2012 8:05 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby Harti79 » Sun Mar 04, 2012 1:37 pm

Thanks with this Patch it works but now i get only black tiles. Any ideas?
Harti79
 
Posts: 90
Joined: Wed Dec 21, 2011 5:48 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby Falc » Fri Apr 06, 2012 2:44 pm

You could keep a transparent tile in your tileset and paint the whole layer with it. I haven't tried this workaround but it should prevent the null pointer exception.

Edit: I tested it and works ok, so it is a valid workaround :D
Falc
 
Posts: 3
Joined: Thu May 12, 2011 4:36 pm

Re: TMX: Handling of TileID==0 leads to NullPointerException

Postby Molkobain » Mon Apr 30, 2012 11:26 pm

Hi,

Thanks you very for letting know this patch from Loffe. It saved me ! :)
Does anyone know if Nicolas plans to incorpore it to the official GLES2 branch ?
Molkobain
 
Posts: 106
Joined: Wed Apr 18, 2012 4:16 pm
Location: France


Return to Bugs

Who is online

Users browsing this forum: No registered users and 3 guests