Skip to content

Commit ec68c6a

Browse files
yaRnMcDonutsAli-RS
authored andcommitted
Replace Exception with warning in TerrainPatch (#1966)
* Replace Excpetion with warning in TerrainPatch PR following up on the discussion in this thread: https://hub.jmonkeyengine.org/t/terrain-collision-exception/46491/6 * Update TerrainPatch.java * Update TerrainPatch.java * Update TerrainPatch.java * Update TerrainPatch.java * Update TerrainPatch.java * Update TerrainPatch.java * Update TerrainPatch.java
1 parent 49efb4d commit ec68c6a

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2020 jMonkeyEngine
2+
* Copyright (c) 2009-2023 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,8 @@
5656
import java.nio.FloatBuffer;
5757
import java.util.HashMap;
5858
import java.util.List;
59+
import java.util.logging.Logger;
60+
import java.util.logging.Level;
5961

6062

6163
/**
@@ -79,6 +81,8 @@
7981
* @author Brent Owens
8082
*/
8183
public class TerrainPatch extends Geometry {
84+
85+
private static final Logger logger = Logger.getLogger(TerrainPatch.class.getName());
8286

8387
protected LODGeomap geomap;
8488
protected int lod = 0; // this terrain patch's LOD
@@ -798,19 +802,22 @@ protected void setLodBottom(int lodBottom) {
798802

799803
@Override
800804
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
801-
if (refreshFlags != 0)
802-
throw new IllegalStateException("Scene graph must be updated" +
803-
" before checking collision");
804-
805-
if (other instanceof BoundingVolume)
806-
if (!getWorldBound().intersects((BoundingVolume)other))
805+
if ((refreshFlags & (RF_BOUND | RF_TRANSFORM)) != 0) {
806+
logger.log(Level.WARNING, "Scene graph must be updated before checking collision");
807+
return 0;
808+
}
809+
810+
if (other instanceof BoundingVolume) {
811+
if (!getWorldBound().intersects((BoundingVolume)other)) {
807812
return 0;
808-
809-
if(other instanceof Ray)
813+
}
814+
}
815+
816+
if (other instanceof Ray) {
810817
return collideWithRay((Ray)other, results);
811-
else if (other instanceof BoundingVolume)
818+
} else if (other instanceof BoundingVolume) {
812819
return collideWithBoundingVolume((BoundingVolume)other, results);
813-
else {
820+
} else {
814821
throw new UnsupportedCollisionException("TerrainPatch cannot collide with "+other.getClass().getName());
815822
}
816823
}

0 commit comments

Comments
 (0)