[osg-users] Heap corruption

Robert Osfield robert.osfield at gmail.com
Thu Sep 3 06:03:04 PDT 2015


Hi Julie,

I'm not why you are using a separate thread here as the syncronization will
likely just serialize the operations anyway, it'll be more efficient to do
all the work in the update callback directly as you won't thash the cache.

As for the cause of the crash, if you running the viewer multi-threaded
(which is the default) then the static objects left in draw traversal will
run in a parallel with the next frame.  Now if the state+drawables being
dispatches in by the draw thread aren't actually static but are being
modified by the update traversal from the main thread (or other thread)
you'll get a conflict.

The way to avoid this conflict is to set the DataVariance on the StateSet
and Drawable objects that you are modifying to DYNAMIC.  The draw traversal
holds back the next frame till all the DYNMAIC StateSet and Drawable are
dispatched to OpenGL thus avoid thread conflict.  An alternative to this
would be to run the viewer SingleThreaded or CullDrawThreadPerContext by
setting the threading model using
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);

Robert.


On 3 September 2015 at 13:06, Julie Green <laroux92 at mail.ru> wrote:

> Hi,
>
> I'm trying to draw a quadric surface, which is modifying each frame, and
> I'm getting a heap corruption error. I guess the problem is in calculating
> function, or in update callback, but can't find it in the debugger.
>
> Code:
>
> void SurfaceCalculationThread::reCalculateSurface()
> {
>         mutex.lock();
>         float x, y, z;
>         int i = 0;
>         float t=time->elapsedTime();
>         for (x = -polygonLength; x <= polygonLength; x += 1.0f)
>         {
>                 for (y = -polygonLength; y <= polygonLength; y += 1.0f)
>                 {
>                         (*oldVertexArray)[i].set((*newVertexArray)[i]);
>                         z = computeZ(x, y, t);
>                         (*newVertexArray)[i].set(osg::Vec3f(x, y, z));
>                         i++;
>                 }
>         }
>         geometry->setVertexArray(oldVertexArray);
>         geometry->setUpdateCallback(new
> UpdateSurfaceCallback(conditionVariable));
>
>         osgUtil::SmoothingVisitor *smoothingVisitor = new
> osgUtil::SmoothingVisitor();
>         smoothingVisitor->smooth(*geometry);
>         smoothingVisitor->setName("normal");
>
>         conditionVariable->wait(&mutex);
>         mutex.unlock();
>
> }
>
> void UpdateSurfaceCallback::operator()(osg::Node *node, osg::NodeVisitor
> *nv)
> {
>         traverse(node, nv);
>         conditionVariable->wakeAll();
> };
>
>
>
>
> Thanks for your help!
>
> Cheers,
> Julie
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=65007#65007
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150903/72335af3/attachment-0003.htm>


More information about the osg-users mailing list