From 6ac87ad1145de56de3e036ae15ebbd31bd7b4b29 Mon Sep 17 00:00:00 2001 From: "Lee1, Ashley (NBCUniversal)" Date: Thu, 7 May 2026 11:23:54 -0700 Subject: [PATCH] Fixes integer overflow problem in light stats (#2268) Co-authored-by: Ashley Lee Signed-off-by: Jon Lanz --- lib/rendering/rndr/RenderStatistics.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/rendering/rndr/RenderStatistics.cc b/lib/rendering/rndr/RenderStatistics.cc index e0d2292..419abbc 100644 --- a/lib/rendering/rndr/RenderStatistics.cc +++ b/lib/rendering/rndr/RenderStatistics.cc @@ -1299,7 +1299,7 @@ void populateLightStats(std::vector& lightStats, float& totalTime, fl int pixelSamplesSqrt = sceneVars.get(scene_rdl2::rdl2::SceneVariables::sPixelSamplesSqrt); int numPixels = sceneVars.get(scene_rdl2::rdl2::SceneVariables::sImageWidth) * sceneVars.get(scene_rdl2::rdl2::SceneVariables::sImageHeight); - int totalPixelSamples = pixelSamplesSqrt*pixelSamplesSqrt * numPixels; + double totalPixelSamples = static_cast(pixelSamplesSqrt)*pixelSamplesSqrt * numPixels; totalTime = 0.0; float totalEfficiency = 0.f; @@ -1321,9 +1321,10 @@ void populateLightStats(std::vector& lightStats, float& totalTime, fl totalEfficiency += lightStat.efficiency; } - avgTimePerLight = totalTime / scene->getLightCount(); - avgEfficiency = totalEfficiency / scene->getLightCount(); - avgLightsChosen = pbrStats.getCounter(pbr::STATS_NUM_LIGHTS_CHOSEN) / totalPixelSamples; + avgTimePerLight = scene->getLightCount() > 0 ? totalTime / scene->getLightCount() : 0.f; + avgEfficiency = scene->getLightCount() > 0 ? totalEfficiency / scene->getLightCount() : 0.f; + avgLightsChosen = totalPixelSamples > 0 ? + pbrStats.getCounter(pbr::STATS_NUM_LIGHTS_CHOSEN) / totalPixelSamples : 0.0; } void RenderStats::logLightStats(const pbr::Statistics& pbrStats, const pbr::Scene* scene,