Skip to content

Commit 2b00e52

Browse files
Fix PointLight infinite radius shader overflow(#2566) (#2570)
* Fix PointLight infinite radius shader overflow(#2566) Clamps infinite, negative, or Not a Number radius to Float.MAX_VALUE / 4f to prevent type overflow in shaders, as discussed in #2566. * Address Requested Changed from Codex * Update PointLight.java --------- Co-authored-by: Ryan McDonough <peanut64646@gmail.com>
1 parent 9665dcf commit 2b00e52

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

jme3-core/src/main/java/com/jme3/light/PointLight.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ public final void setRadius(float radius) {
165165
if (radius < 0) {
166166
throw new IllegalArgumentException("Light radius cannot be negative");
167167
}
168-
169-
if (radius == Float.POSITIVE_INFINITY) {
170-
radius = Float.MAX_VALUE;
168+
if(Float.isNaN(radius)){
169+
throw new IllegalArgumentException("Light radius cannot be a NaN (Not a Number) value");
171170
}
171+
172+
float maxSafeRadius = Float.MAX_VALUE / 4.0f;
173+
radius = Math.min(radius, maxSafeRadius); // Caps radius to a safe large value; avoids overflow in shaders from values reaching max float value
172174

173175
this.radius = radius;
174176
if (radius != 0f) {
@@ -259,3 +261,5 @@ public String toString() {
259261
+ "]";
260262
}
261263
}
264+
265+

0 commit comments

Comments
 (0)