From 0a37744a5432373720a4c2c04fffa6e6097e6f28 Mon Sep 17 00:00:00 2001 From: flashk Date: Wed, 3 Oct 2018 11:32:10 -0700 Subject: [PATCH] Fix for GifImageStream::setReferenceTime Setting the reference time greater than the duration of a gif would cause a crash. Also, the current reference time is not immediately updated when manually setting the reference time. --- src/osgPlugins/gif/ReaderWriterGIF.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index 7e438dc3f..d9369902c 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -112,14 +112,15 @@ public: int i=1; int framePos = static_cast(time*100.0/_multiplier); - if ( framePos>=(int)_length ) - framePos = _length; + framePos = osg::clampBetween(framePos, 0, (int)_length); + _currentLength = framePos; + std::vector::iterator lastFrame = --_dataList.end(); std::vector::iterator it; for ( it=_dataList.begin(); it!=_dataList.end(); it++,i++ ) { framePos -= (*it)->delay; - if ( framePos<0 ) + if ( framePos<0 || it == lastFrame ) break; } _dataNum = i-1;