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:
(44.61 KiB) Downloaded 445 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(
  4. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLayer.initializeTMXTilesFromDataString(
  5. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXParser.endElement(
  6. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.endElement(
  7. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
  8. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.parseFragment(
  9. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatParser.parseDocument(
  10. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatReader.parse(
  11. E/AndroidRuntime(2092):         at org.apache.harmony.xml.ExpatReader.parse(
  12. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLoader.load(
  13. E/AndroidRuntime(2092):         at org.andengine.extension.tmx.TMXLoader.loadFromAsset(
Parsed in 0.000 seconds, using GeSHi

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...
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. }
Parsed in 0.012 seconds, using GeSHi

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. }
Parsed in 0.011 seconds, using GeSHi

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.
Posts: 3
Joined: Thu May 12, 2011 4:36 pm

Re: Crashes when loading a TMX with transparent tiles

Postby dpod42 » Sat May 10, 2014 12:18 am

I found this post while looking for a solution on Google for my errors. I've since solved my problem and am leaving this here for anyone who might stumble upon this post like I did.

I was getting NullPointerException and Unknown binder error code. 0xfffffff7

The problem was that I created a TMX file with multiple image layers. One of those layers was a blank layer. It had absoultely no tiles on it. Blank tiles are okay for anchor center (which is what I'm using), but, apparently, you cannot have blank layers. Woops! :lol:
Posts: 54
Joined: Fri Apr 25, 2014 6:30 am

Return to Bugs

Who is online

Users browsing this forum: No registered users and 4 guests