[osg-users] [osg-submissions] division by zero in osgParticle/FluidProgram.cpp

Robert Osfield robert.osfield at gmail.com
Fri Mar 13 03:16:27 PDT 2009

Hi Csaba,

Thanks for the fix. This helps me understand the nature and location
of the problem.  Reviewing the changes and the original code I'm
thinking it might be simpler to just refactor the code block so the
division by wind_accel.length2() could be delayed, and have the if ()
statement refactored by moving the divisor to the other side of the <
expression :

            double compenstated_dt = dt;
            if (relative_wind.length2() < dt*dt*wind_accel.length2())
                double critical_dt2 =
                osg::notify(osg::NOTICE)<<"** Could be critical:
dt="<<dt<<" critical_dt="<<sqrtf(critical_dt2)<<std::endl;
                compenstated_dt = sqrtf(critical_dt2)*0.8f;

Does this change make sense to you?  If wind_accel.length2() is zero
then the division will never take place, chances of an overflow should
be avoided as well.  The changed file is attached, could you try this
out on your models/app.  I've done the standard example tests here and
they all work, but then they never highlighted a error so I can't
confirm a fix.


On Thu, Mar 12, 2009 at 6:08 PM, Csaba Halász <csaba.halasz at gmail.com> wrote:
> Hi Robert and all,
> Attached modification works around a division by zero. NOTE: it does
> *not* fix potential overflow still lurking there if the wind_accel is
> a small vector (which it probably can be, if I have run into it being
> zero...)
> --
> Csaba
> _______________________________________________
> osg-submissions mailing list
> osg-submissions at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FluidProgram.cpp
Type: text/x-c++src
Size: 2095 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20090313/0966f545/attachment-0002.cpp>

More information about the osg-users mailing list