NullPointerException on terrain.getMaterial(Vector3f)

I have copied the code from PaintTerrainToolAction.java to make an in-game editor and when I fired the paint event, the application shut down with a NullPointerException at the line





matParam = terrain.getMaterial(loc).getParam(“AlphaMap”);





Where loc is calculated from the method getWorldIntersection, from the TerrainTestModifyHeight.java and getMaterial(loc) returns null.



The terrain is an instance of TerrainGrid and the material set is using the TerrainLighting map definition.



Is this a known issue?

It’s probably not finding the proper tile in the cache. Run the debugger and look through TerrainGrid.getMaterial(). I’m guessing something is off with your coordinate you are passing in and it is not finding a tile, or it is mis-calculating the cell in TerrainGrid.

Well, I replaced TerrainGrid with an instance of TerrainQuad, and now it cannot find the alpha map image.





if (matParam == null || matParam.getValue() == null) {

return null;

}





Where matParam.getValue() returns null. Well, I thought it would be simpler :slight_smile:



On another note, if this vector works for adjusting terrain height, why doesn’t it work for finding the terrain alpha map?



** Update **



I would really appreciate some information as to why terrain.getMaterial(loc) return null every time the vector is not [0, 0, 0]? The API declares the method’s parameter as getMaterial(Vector3f worldLocation), which is what the value passed to it is. But when I call getTileCell(Vector3f location), it returns some out of bound values. What kind of transformation to the vector do I need to perform before I call getMaterial?