From f268bc13f1e69e150e26871af2ae308615200607 Mon Sep 17 00:00:00 2001 From: Frederic Chardon Date: Wed, 1 Jul 2020 11:04:18 +0000 Subject: [PATCH] Do not set particle lifetime to 0 (#5472) --- CHANGELOG.md | 1 + components/nifosg/nifloader.cpp | 13 +++++++++---- components/nifosg/particle.cpp | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1b61a7c..633685887 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Bug #5441: Enemies can't push a player character when in critical strike stance Bug #5451: Magic projectiles don't disappear with the caster Bug #5452: Autowalk is being included in savegames + Bug #5472: Mistify mod causes CTD in 0.46 on Mac Bug #5479: NPCs who should be walking around town are standing around without walking Bug #5484: Zero value items shouldn't be able to be bought or sold for 1 gold Bug #5485: Intimidate doesn't increase disposition on marginal wins diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 88e89b400..6830e792f 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -923,15 +923,18 @@ namespace NifOsg osg::BoundingBox box; int i=0; - for (std::vector::const_iterator it = partctrl->particles.begin(); - iactiveCount && it != partctrl->particles.end(); ++it, ++i) + for (const auto& particle : partctrl->particles) { - const Nif::NiParticleSystemController::Particle& particle = *it; + if (i++ >= particledata->activeCount) + break; + + if (particle.lifespan <= 0) + continue; ParticleAgeSetter particletemplate(std::max(0.f, particle.lifetime)); osgParticle::Particle* created = partsys->createParticle(&particletemplate); - created->setLifeTime(std::max(0.f, particle.lifespan)); + created->setLifeTime(particle.lifespan); // Note this position and velocity is not correct for a particle system with absolute reference frame, // which can not be done in this loader since we are not attached to the scene yet. Will be fixed up post-load in the SceneManager. @@ -970,6 +973,8 @@ namespace NifOsg osgParticle::ConstantRateCounter* counter = new osgParticle::ConstantRateCounter; if (partctrl->emitFlags & Nif::NiParticleSystemController::NoAutoAdjust) counter->setNumberOfParticlesPerSecondToCreate(partctrl->emitRate); + else if (partctrl->lifetime == 0 && partctrl->lifetimeRandom == 0) + counter->setNumberOfParticlesPerSecondToCreate(0); else counter->setNumberOfParticlesPerSecondToCreate(partctrl->numParticles / (partctrl->lifetime + partctrl->lifetimeRandom/2)); diff --git a/components/nifosg/particle.cpp b/components/nifosg/particle.cpp index 804a8f8ab..f71dcdd96 100644 --- a/components/nifosg/particle.cpp +++ b/components/nifosg/particle.cpp @@ -125,7 +125,7 @@ void ParticleShooter::shoot(osgParticle::Particle *particle) const particle->setVelocity(dir * vel); // Not supposed to set this here, but there doesn't seem to be a better way of doing it - particle->setLifeTime(mLifetime + mLifetimeRandom * Misc::Rng::rollClosedProbability()); + particle->setLifeTime(std::max(std::numeric_limits::epsilon(), mLifetime + mLifetimeRandom * Misc::Rng::rollClosedProbability())); } GrowFadeAffector::GrowFadeAffector(float growTime, float fadeTime) @@ -184,6 +184,7 @@ ParticleColorAffector::ParticleColorAffector(const ParticleColorAffector ©, void ParticleColorAffector::operate(osgParticle::Particle* particle, double /* dt */) { + assert(particle->getLifeTime() > 0); float time = static_cast(particle->getAge()/particle->getLifeTime()); osg::Vec4f color = mData.interpKey(time); float alpha = color.a();