Crashes when loading a TMX with transparent tiles

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

Crashes when loading a TMX with transparent tiles

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

EDIT: Sorry, i didn't realize that there was another topic: bugs-gles2/tmx-handling-of-tileid-0-leads-to-nullpointerexception-t6862.html

I think i've found a bug related with TMX maps and transparent tiles.

The map i'm using contains these layers:
- lower: full of ground-type tiles (water, grass...). It has no transparent tiles
- upper: where the trees, buildings and that kind of things are placed.There are a lot of transparent/unused tiles.

This is the map file with the tileset:
tmx.zip
(44.61 KiB) Downloaded 119 times


When i try to load it from AndEngine, it simply crashes and LogCat displays the following error:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. E/AndroidRuntime(2092): FATAL EXCEPTION: UpdateThread
  2. E/AndroidRuntime(2092): java.lang.NullPointerException
  3. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLayer.addTileByGlobalTileID(TMXLayer.java:265)
  4. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLayer.initializeTMXTilesFromDataString(TMXLayer.java:238)
  5. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXParser.endElement(TMXParser.java:197)
  6. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:158)
  7. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
  8. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
  9. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
  10. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
  11. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
  12. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLoader.load(TMXLoader.java:117)
  13. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLoader.loadFromAsset(TMXLoader.java:102)
  14.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


If i delete the "upper" layer (the one without transparent tiles) from the tmx file, it loads correctly.

Taking a look to AndEngine's TMXLayer class...
org.andengine.extension.tmx.TMXLayer.addTileByGlobalTileID(TMXLayer.java:265):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if(this.mTexture == null) {
  2.         this.mTexture = tmxTileTextureRegion.getTexture();
  3.         super.initBlendFunction(this.mTexture);
  4. } else {
  5.         if(this.mTexture != tmxTileTextureRegion.getTexture()) {
  6.                 throw new AndEngineRuntimeException("All TMXTiles in a TMXLayer need to be in the same TMXTileSet.");
  7.         }
  8. }
  9.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


A few lines above that, i found this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final ITextureRegion tmxTileTextureRegion;
  2. if(pGlobalTileID == 0) {
  3.         tmxTileTextureRegion = null;
  4. } else {
  5.         tmxTileTextureRegion = tmxTiledMap.getTextureRegionFromGlobalTileID(pGlobalTileID);
  6. }
  7.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


When a transparent tile is found (pGlobalTileID), tmxTileTextureRegion is set to null. Then why the code tries to do this.mTexture = tmxTileTextureRegion.getTexture() for transparent tiles? That is what is causing a NullPointerException.

Is that normal and should i keep a transparent tile in my tileset in order to avoid 0 globalTileIDs, or is it a bug?

IMHO, 0 globalTileIDs should be ignored, at least the process related with texture loading.

Note: I don't have much experience with AndEngine, sorry if i misunderstood something.
Falc
 
Posts: 3
Joined: Thu May 12, 2011 4:36 pm

Return to Bugs

Who is online

Users browsing this forum: No registered users and 4 guests