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

SCHWERWIEGEND: null

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(TerrainGrid.java:209)<br /> at com.jme3.terrain.geomipmap.TerrainGrid.initialize(TerrainGrid.java:123)<br /> at online.newhorizons.l3dt.Test.simpleInitApp(Test.java:95)<br /> at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:223)<br /> at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:124)<br /> at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:200)<br /> at java.lang.Thread.run(Unknown 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(Grayscale16BitHeightMap.java:56)<br /> at com.jme3.terrain.heightmap.Grayscale16BitHeightMap.load(Grayscale16BitHeightMap.java:43)<br /> at com.jme3.terrain.heightmap.ImageBasedHeightMapGrid.getHeightMapAt(ImageBasedHeightMapGrid.java:66)<br /> at com.jme3.terrain.geomipmap.TerrainGrid$UpdateQuadCache.run(TerrainGrid.java:62)<br /> at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)<br /> at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)<br /> at java.util.concurrent.FutureTask.run(Unknown Source)<br /> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)<br /> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown 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 com.jme3.app.Application handleError<br /> SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.terrain.geomipmap.TerrainGrid.update(TerrainGrid.java:137)

at com.jme3.terrain.geomipmap.TerrainLodControl.controlUpdate(TerrainLodControl.java:98)

at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:86)

at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:494)

at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:612)

at com.jme3.scene.Node.updateLogicalState(Node.java:151)

at com.jme3.scene.Node.updateLogicalState(Node.java:158)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:249)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:173)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:218)

at java.lang.Thread.run(Unknown Source)



http://wiki.nh-game.net/upload/en/2011/6/gimpheigmap-17001659.png

Also a small but important suggestion



Index: src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java

===================================================================

— src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java (revision 7640)

+++ src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java (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 />
    

this.updateChildrens(camCell);

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

l.gridMoved(camCell);





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: