From 6011bc43075cd29070bb7c6c2315d5144aa919ba Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 23 Feb 2016 10:12:31 +0000 Subject: [PATCH] From Jannik Heller, osgParticle freeze on cull fix, ammended by Robert Osfield to make if statements a little more readable. --- src/osgParticle/ParticleProcessor.cpp | 4 +++- src/osgParticle/ParticleSystemUpdater.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/osgParticle/ParticleProcessor.cpp b/src/osgParticle/ParticleProcessor.cpp index 0f2a8622b..19ed2f859 100644 --- a/src/osgParticle/ParticleProcessor.cpp +++ b/src/osgParticle/ParticleProcessor.cpp @@ -99,10 +99,12 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv) _currentTime += t - _t0; // process only if the particle system is not frozen/culled + // We need to allow at least 2 frames difference, because the particle system's lastFrameNumber + // is updated in the draw thread which may not have completed yet. if (alive && _enabled && !_ps->isFrozen() && - ((_ps->getLastFrameNumber()+1) >= (nv.getFrameStamp()->getFrameNumber()) || !_ps->getFreezeOnCull())) + (!_ps->getFreezeOnCull() || ((nv.getFrameStamp()->getFrameNumber()-_ps->getLastFrameNumber()) <= 2)) ) { // initialize matrix flags _need_ltw_matrix = true; diff --git a/src/osgParticle/ParticleSystemUpdater.cpp b/src/osgParticle/ParticleSystemUpdater.cpp index 1c826e870..84dc9d234 100644 --- a/src/osgParticle/ParticleSystemUpdater.cpp +++ b/src/osgParticle/ParticleSystemUpdater.cpp @@ -41,7 +41,10 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv) ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex())); - if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull())) + // We need to allow at least 2 frames difference, because the particle system's lastFrameNumber + // is updated in the draw thread which may not have completed yet. + if (!ps->isFrozen() && + (!ps->getFreezeOnCull() || ((nv.getFrameStamp()->getFrameNumber()-ps->getLastFrameNumber()) <= 2)) ) { ps->update(t - _t0, nv); }