From 75b03628ecc865297df22dd50c3bfdc527dbe718 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Mon, 21 Sep 2026 16:21:19 +0300 Subject: [PATCH] Fix division by zero in cLighting::Animate before Init --- Source/Render/src/lighting.cpp | 19 ++++++++++++------- Source/Units/SecondGun.cpp | 6 ++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Source/Render/src/lighting.cpp b/Source/Render/src/lighting.cpp index f51fe38c1..aa4cbd424 100644 --- a/Source/Render/src/lighting.cpp +++ b/Source/Render/src/lighting.cpp @@ -143,13 +143,18 @@ void cLighting::Animate(float dt) { dt*=1e-3f; time+=dt; - while(time>=param.generate_time) - { - time-=param.generate_time; - PreGenerate g; - g.pos_begin=pos_begin; - g.pos_end=pos_end[rnd() % pos_end.size()]; - pre_generate.push_back(g); + if (pos_end.empty()) { + //Init() not called yet, nothing to generate arcs towards + time = min(time, param.generate_time); + } else { + while(time>=param.generate_time) + { + time-=param.generate_time; + PreGenerate g; + g.pos_begin=pos_begin; + g.pos_end=pos_end[rnd() % pos_end.size()]; + pre_generate.push_back(g); + } } float fade_dt=dt/param.fade_time; diff --git a/Source/Units/SecondGun.cpp b/Source/Units/SecondGun.cpp index 7ddd9a33a..01b0fb0eb 100644 --- a/Source/Units/SecondGun.cpp +++ b/Source/Units/SecondGun.cpp @@ -2211,6 +2211,12 @@ void terWeaponLighting::quant() //the fire is delayed thanks to startFireDelay() so it wont kill before arc is displayed if (!lighting_) { lighting_ = new cLighting; + //Init before attaching so Animate() never sees empty pos_end + Vect3f v0,v1; + aimController()->getTargetingPosition(v0,v1); + std::vector vect; + vect.push_back(target_pos); + lighting_->Init(v0, vect, setup().laserWidth / 2.0f); terScene->AttachObj(lighting_); } else { target_->SetHotCount(5);