ZhouWeikuan/cocos2d — Issue #47: CCTMXLayer > CCTextureAtlas IndexOutOfBoundsException
Author: savethejets
Created: 2011-11-08 06:03:05+00:00
State: open

I'm getting an IndexOutOfBoundsException when I try and load my Tiled maps.

I'm using gzip format and all that jazz. It looks like it might have something to do with the fact that the indices var is a shortbuffer array and that the (int) index is greater than Short.MAX_VALUE; ( It looks like it's flipping to the negative number.) see below.

I'm digging into this, but has anyone else run into this? (or possibly fixed this already??? :D)

public void initIndices() {
for (int i = 0; i < capacity_; i++) {
if (ccConfig.CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP) {
indices.put((short) (i * 6 + 0), (short) (i * 4 + 0));
indices.put((short) (i * 6 + 1), (short) (i * 4 + 0));
indices.put((short) (i * 6 + 2), (short) (i * 4 + 2));
indices.put((short) (i * 6 + 3), (short) (i * 4 + 1));
indices.put((short) (i * 6 + 4), (short) (i * 4 + 3));
indices.put((short) (i * 6 + 5), (short) (i * 4 + 3));
} else {
indices.put((short) (i * 6 + 0), (short) (i * 4 + 0)); <---- (i * 6 + whatever) cast to a short will sometimes give a negative number since you have an int larger than Short.MAX_VALUE;
indices.put((short) (i * 6 + 1), (short) (i * 4 + 1));
indices.put((short) (i * 6 + 2), (short) (i * 4 + 2));

// inverted index.
indices.put((short) (i * 6 + 5), (short) (i * 4 + 1));
indices.put((short) (i * 6 + 4), (short) (i * 4 + 2));
indices.put((short) (i * 6 + 3), (short) (i * 4 + 3));
}
}
indices.position(0);
}