Просмотр исходного кода

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 <[email protected]>
hayden9329 2 дней назад
Родитель
Сommit
2b00e52d0d
1 измененных файлов с 7 добавлено и 3 удалено
  1. 7 3
      jme3-core/src/main/java/com/jme3/light/PointLight.java

+ 7 - 3
jme3-core/src/main/java/com/jme3/light/PointLight.java

@@ -165,10 +165,12 @@ public class PointLight extends Light {
         if (radius < 0) {
             throw new IllegalArgumentException("Light radius cannot be negative");
         }
-        
-        if (radius == Float.POSITIVE_INFINITY) {
-            radius = Float.MAX_VALUE;
+        if(Float.isNaN(radius)){
+            throw new IllegalArgumentException("Light radius cannot be a NaN (Not a Number) value");
         }
+
+        float maxSafeRadius = Float.MAX_VALUE / 4.0f;
+        radius = Math.min(radius, maxSafeRadius); // Caps radius to a safe large value; avoids overflow in shaders from values reaching max float value   
         
         this.radius = radius;
         if (radius != 0f) {
@@ -259,3 +261,5 @@ public class PointLight extends Light {
                 + "]";
     }
 }
+
+