From 761770d4eb961d01b9c0004c1742c302af2fd2be Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 12 Dec 2019 09:16:45 +0800 Subject: [PATCH] Fix divide by zero crash in zone lighter --- code/nel/src/3d/zone_lighter.cpp | 53 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/code/nel/src/3d/zone_lighter.cpp b/code/nel/src/3d/zone_lighter.cpp index 5dd322cc8..570ba1075 100644 --- a/code/nel/src/3d/zone_lighter.cpp +++ b/code/nel/src/3d/zone_lighter.cpp @@ -1179,36 +1179,43 @@ void CZoneLighter::light (CLandscape &landscape, CZone& output, uint zoneToLight // Set the thread state _LastPatchComputed.resize (_ProcessCount); - // Launch threads - uint process; - for (process=0; process<_ProcessCount; process++) + if (patchCount) { - // Last patch - uint lastPatch=firstPatch+patchCountByThread; - lastPatch %= patchCount; + // Launch threads + uint process; + for (process = 0; process < _ProcessCount; process++) + { + // Last patch + uint lastPatch = firstPatch + patchCountByThread; + lastPatch %= patchCount; - // Last patch computed - _LastPatchComputed[process] = firstPatch; + // Last patch computed + _LastPatchComputed[process] = firstPatch; - // Create a thread - CLightRunnable *runnable = new CLightRunnable (process, this, &description); - IThread *pThread=IThread::create (runnable); - runnable->Thread = pThread; + // Create a thread + CLightRunnable *runnable = new CLightRunnable(process, this, &description); + IThread *pThread = IThread::create(runnable); + runnable->Thread = pThread; - // New first patch - firstPatch=lastPatch; + // New first patch + firstPatch = lastPatch; - // Launch - pThread->start(); - } + // Launch + pThread->start(); + } - // Wait for others processes - while (_ProcessExited!=_ProcessCount) - { - nlSleep (1000); + // Wait for others processes + while (_ProcessExited != _ProcessCount) + { + nlSleep(1000); - // Call the progress callback - progress ("Lighting patches", (float)_NumberOfPatchComputed/(float)_PatchInfo.size()); + // Call the progress callback + progress("Lighting patches", (float)_NumberOfPatchComputed / (float)_PatchInfo.size()); + } + } + else + { + nlwarning("Empty zone"); } // Reset old thread mask