GridTerrain problem

Hi, I’m currently having hard problems to get ridTerrain to work with my (finally) generated Heighmaps, actually there seems to be a problem with loading the Images, but I’m not sure why. Png is set to 16bit grayscale when exporting (also gimp is reporting this).

17.06.2011 00:14:45 com.jme3.terrain.heightmap.ImageBasedHeightMapGrid getHeightMapAt

INFO: Loading heightmap from file: heighmap_x0y0.png

17.06.2011 00:14:45 com.jme3.terrain.geomipmap.TerrainGrid updateChildrens


java.util.concurrent.ExecutionException: java.lang.ClassCastException: [S cannot be cast to [B<br /> at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)<br /> at java.util.concurrent.FutureTask.get(Unknown Source)<br /> at com.jme3.terrain.geomipmap.TerrainGrid.updateChildrens(<br /> at com.jme3.terrain.geomipmap.TerrainGrid.initialize(<br /> at online.newhorizons.l3dt.Test.simpleInitApp(<br /> at<br /> at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(<br /> at<br /> at Source)<br /> Caused by: java.lang.ClassCastException: [S cannot be cast to [B<br /> at sun.awt.image.ByteInterleavedRaster.getDataElements(Unknown Source)<br /> at com.jme3.terrain.heightmap.Grayscale16BitHeightMap.load(<br /> at com.jme3.terrain.heightmap.Grayscale16BitHeightMap.load(<br /> at com.jme3.terrain.heightmap.ImageBasedHeightMapGrid.getHeightMapAt(<br /> at com.jme3.terrain.geomipmap.TerrainGrid$<br /> at java.util.concurrent.Executors$ Source)<br /> at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)<br /> at Source)<br /> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)<br /> at java.util.concurrent.ThreadPoolExecutor$ Source)<br /> … 1 more<br /> 17.06.2011 00:14:45 com.jme3.scene.Node attachChild<br /> INFO: Child (terrain) attached to this node (Root Node)<br /> 17.06.2011 00:14:45 handleError<br /> SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at com.jme3.terrain.geomipmap.TerrainGrid.update(

at com.jme3.terrain.geomipmap.TerrainLodControl.controlUpdate(

at com.jme3.scene.control.AbstractControl.update(

at com.jme3.scene.Spatial.runControlUpdate(

at com.jme3.scene.Spatial.updateLogicalState(

at com.jme3.scene.Node.updateLogicalState(

at com.jme3.scene.Node.updateLogicalState(


at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(


at Source)

Also a small but important suggestion

Index: src/terrain/com/jme3/terrain/geomipmap/


— src/terrain/com/jme3/terrain/geomipmap/ (revision 7640)

+++ src/terrain/com/jme3/terrain/geomipmap/ (working copy)

@@ -119,7 +119,10 @@


public void initialize(Vector3f location) {

  •    Vector3f camCell = this.getCell(location);<br />
  •    if(this.material == null){<br />
  •    	throw new RuntimeException("Material must be set prior to call of initialize");<br />
  •    }<br />
  •   Vector3f camCell = this.getCell(location);<br />


for (TerrainGridListener l : this.listeners.values()) {


Cause if you first call initalize then set the Material you get a crash at some inner Quad Class, leaving you somewhat in confusion what actualy went wrong.

Hey, why the output is showing class cast exceptions?

Yes, that is exactly what I’m wondering about, since I don’t see what might cause it.

The exception occours into the updateChildrens method. Debug it and enter into methods to find the wrong class cast.

Well I found the reason, at the point where the image is converted to the hieghmap 2d array there is a cast to a short array. I don’t fully understand why i get there a error, however i found out that it dissapears, if I export the heighmap as 8bit grayscale.(even though it is loaded into a 16bitgrayscale heighmap)

this exception is really strange… It seems to me, that it tried to convert short array to byte array. But I do not use bytes anywhere. And short is really 16 bit. :confused: I’m creating the test images by simply filling a BufferedImage. Could you please attach a problematic image, so i can take a look at it?

I’ll make the proposed addition :slight_smile: