Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 14, 2019 6:51 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Jan 07, 2013 5:19 pm 
Offline

Joined: Mon Jan 07, 2013 5:12 pm
Posts: 1
When loading tiled maps layers where there is no tile set for slots getTiles() will crash with array out of bounds exception.

Here is problem:

Original code Layer.java line 342
Code:
   public ArrayList<Tile> getTiles() throws SlickException {
      if (tmap == null) {
         throw new SlickException(
               "This method can only be used with Layers loaded using TiledMapPlus");
      }
      ArrayList<Tile> tiles = new ArrayList<Tile>();
      for (int x = 0; x < this.width; x++) {
         for (int y = 0; y < this.height; y++) {
                    String tilesetName = tmap.tileSets.get(this.data[x][y][0]).name;
                    Tile t = new Tile(x, y, this.name, y, tilesetName);
                    tiles.add(t);
         }
      }
      return tiles;
   }


And here is fixed method:

Code:
   public ArrayList<Tile> getTiles() throws SlickException {
      if (tmap == null) {
         throw new SlickException(
               "This method can only be used with Layers loaded using TiledMapPlus");
      }
      ArrayList<Tile> tiles = new ArrayList<Tile>();
      for (int x = 0; x < this.width; x++) {
         for (int y = 0; y < this.height; y++) {
                int index = this.data[x][y][0];
                if (index != -1) {
                    String tilesetName = tmap.tileSets.get(index).name;
                    Tile t = new Tile(x, y, this.name, y, tilesetName);
                    tiles.add(t);
                }
         }
      }
      return tiles;
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group