<div dir="ltr"><div><div><div>Hi Julie,<br><br></div>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.<br><br></div>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. <br><br>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);<br><br></div>Robert.<br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 September 2015 at 13:06, Julie Green <span dir="ltr"><<a href="mailto:laroux92@mail.ru" target="_blank">laroux92@mail.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
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.<br>
<br>
Code:<br>
<br>
void SurfaceCalculationThread::reCalculateSurface()<br>
{<br>
mutex.lock();<br>
float x, y, z;<br>
int i = 0;<br>
float t=time->elapsedTime();<br>
for (x = -polygonLength; x <= polygonLength; x += 1.0f)<br>
{<br>
for (y = -polygonLength; y <= polygonLength; y += 1.0f)<br>
{<br>
(*oldVertexArray)[i].set((*newVertexArray)[i]);<br>
z = computeZ(x, y, t);<br>
(*newVertexArray)[i].set(osg::Vec3f(x, y, z));<br>
i++;<br>
}<br>
}<br>
geometry->setVertexArray(oldVertexArray);<br>
geometry->setUpdateCallback(new UpdateSurfaceCallback(conditionVariable));<br>
<br>
osgUtil::SmoothingVisitor *smoothingVisitor = new osgUtil::SmoothingVisitor();<br>
smoothingVisitor->smooth(*geometry);<br>
smoothingVisitor->setName("normal");<br>
<br>
conditionVariable->wait(&mutex);<br>
mutex.unlock();<br>
<br>
}<br>
<br>
void UpdateSurfaceCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)<br>
{<br>
traverse(node, nv);<br>
conditionVariable->wakeAll();<br>
};<br>
<br>
<br>
<br>
<br>
Thanks for your help!<br>
<br>
Cheers,<br>
Julie<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=65007#65007" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=65007#65007</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>