The AbstractHeightMap.smooth(float np) method fails with an ArrayIndexOutOfBoundsException when called on a loaded heightmap (I tried it personally with HillHeightMap and MidpointDisplacementHeightMap, so I assume it will do the same with the rest). I was using a size of 512.
Stacktrace:
java.lang.ArrayIndexOutOfBoundsException: 262145
at com.jme3.terrain.heightmap.AbstractHeightMap.smooth(AbstractHeightMap.java:426)
at jme3test.terrain.TerrainTest.simpleInitApp(TerrainTest.java:131)
…
I looked into the code, and it appears that this part:
[java]for (int d = 0; d < 8; d++) {
int i = x + dxs[d];
int j = y + dys[d];
if (i < 0 || i > size) {
continue;
}
if (j < 0 || j > size) {
continue;
}
neighNumber++;
neighAverage += heightData;
}[/java]
needs to be changed to this:
[java]for (int d = 0; d < 8; d++) {
int i = x + dxs[d];
int j = y + dys[d];
if (i < 0 || i >= size) {
continue;
}
if (j < 0 || j >= size) {
continue;
}
neighNumber++;
neighAverage += heightData;
}[/java]
(‘i > size’ is changed to ‘i >= size’ and ‘j > size’ is changed to ‘j >= size’)
I’m not familiar with committing so I can’t commit that change myself, but I wanted to post here so someone who CAN fix it could do so. I’m using today’s nightly build.