From 615727774b643ebef3f076ee8907f7c78a1def9f Mon Sep 17 00:00:00 2001 From: hkitzmiller Date: Sun, 30 Nov 2025 22:48:00 -0500 Subject: [PATCH 1/3] 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. --- jme3-core/src/main/java/com/jme3/light/PointLight.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/light/PointLight.java b/jme3-core/src/main/java/com/jme3/light/PointLight.java index 440a45a740..a215409148 100644 --- a/jme3-core/src/main/java/com/jme3/light/PointLight.java +++ b/jme3-core/src/main/java/com/jme3/light/PointLight.java @@ -165,11 +165,11 @@ public final void setRadius(float radius) { if (radius < 0) { throw new IllegalArgumentException("Light radius cannot be negative"); } - - if (radius == Float.POSITIVE_INFINITY) { - radius = Float.MAX_VALUE; + + // Fix #2566 - Prevent shader overflow with infinite or invalid radius + if (radius == Float.POSITIVE_INFINITY || radius < 0f || Float.isNaN(radius)) { + radius = Float.MAX_VALUE / 4f; // Safe large value, avoids overflow in shaders } - this.radius = radius; if (radius != 0f) { this.invRadius = 1f / radius; From d1a27033846c7c5d8117c79f15aeca101afa28df Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Wed, 21 Jan 2026 17:58:43 -0500 Subject: [PATCH 2/3] Address Requested Changed from Codex --- .../src/main/java/com/jme3/light/PointLight.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/light/PointLight.java b/jme3-core/src/main/java/com/jme3/light/PointLight.java index a215409148..1b8015fe74 100644 --- a/jme3-core/src/main/java/com/jme3/light/PointLight.java +++ b/jme3-core/src/main/java/com/jme3/light/PointLight.java @@ -165,11 +165,13 @@ public final void setRadius(float radius) { if (radius < 0) { throw new IllegalArgumentException("Light radius cannot be negative"); } - - // Fix #2566 - Prevent shader overflow with infinite or invalid radius - if (radius == Float.POSITIVE_INFINITY || radius < 0f || Float.isNaN(radius)) { - radius = Float.MAX_VALUE / 4f; // Safe large value, avoids overflow in shaders + if(Float.isNaN(radius)){ + throw new IllegalArgumentException("Light radius cannot be a NaN (Not a Number) value"); } + // Prevent shader overflow with infinite or invalid radius + if (radius == Float.POSITIVE_INFINITY || radius > Float.MAX_VALUE / 4.0f) { + radius = Float.MAX_VALUE / 4.0f; // Safe large value, avoids overflow in shaders + } this.radius = radius; if (radius != 0f) { this.invRadius = 1f / radius; @@ -259,3 +261,4 @@ public String toString() { + "]"; } } + From 33bd955bdd1d944e156683f547ee167b783a28c5 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Wed, 21 Jan 2026 18:24:24 -0500 Subject: [PATCH 3/3] Update PointLight.java --- jme3-core/src/main/java/com/jme3/light/PointLight.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/light/PointLight.java b/jme3-core/src/main/java/com/jme3/light/PointLight.java index 1b8015fe74..37748f48d1 100644 --- a/jme3-core/src/main/java/com/jme3/light/PointLight.java +++ b/jme3-core/src/main/java/com/jme3/light/PointLight.java @@ -168,10 +168,10 @@ public final void setRadius(float radius) { if(Float.isNaN(radius)){ throw new IllegalArgumentException("Light radius cannot be a NaN (Not a Number) value"); } - // Prevent shader overflow with infinite or invalid radius - if (radius == Float.POSITIVE_INFINITY || radius > Float.MAX_VALUE / 4.0f) { - radius = Float.MAX_VALUE / 4.0f; // Safe large value, avoids overflow in shaders - } + + 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) { this.invRadius = 1f / radius; @@ -262,3 +262,4 @@ public String toString() { } } +