<div dir="ltr"><div>Hi Rakesh,</div><div><br></div><div>I don't think we can provide much direct insight, you have the whole application and data to test against, while we just have a snippet without any wider information.  The crash could be caused by anything.</div><div><br></div><div>The best we can do is recommend tools/strategies to reproduce the crash or pick up on race conditions.  I only work under Linux these days and use valgrind --tool=helgrind to pick up on threading issues, this works pretty well for catching obscure difficult to catch in testing problems.  I'm sure there will be similar tools under Windows, but can't provide any guidance on this as I'm not a Windows user.<br></div><div><br></div><div>The other thing you could look at is changing the way you are implementing things.  Personally when handling this type of user interaction -> generation of scene graph in real-time I accumulate the user input in a thread safe queue then read from this in the update/event traversal, this then updates the scene graph in a synchronous way avoiding any threading issues.<br></div><div><br></div><div>The OSG also allows you create custom events and inject them in the viewer's EventQueue.  The osc plugin implements a custom event approach, with it providing a custom osgGA::Device that provide interface that the viewer can use to poll the device.  You needn't go this approach, and may just way over complicate the task, but for certain types of apps being able to decouple the device and events makes it easier mix and match devices and event handling.<br></div><div><br></div><div>Robert.<br></div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 4 Oct 2019 at 19:24, Rakesh Prasad <<a href="mailto:rptutor2012@gmail.com">rptutor2012@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
I have a code which renders a progressive line strip. When the line strip is unmasked to display it crashes on some machines. I use osg 3.6.4 with MFC Visual Studio 2019 with V142. The same problem was observed on osg 3.4.0 with MFC and Visual Studio 2013 v120. I am completely clueless as why it would crash since its not on my machine. I dont have the crash stack and other variable values. I have some observations.I will list my code and try to explain as best as possible.<br>
I migrated from osg 3.4.0 hoping 3.6.4 will resolve the issue.<br>
<br>
createHUDClubHdPts is called to create the scenegraph with the arrays. After which every frame AddCurPtToHandClubPath is called. This function updates the point in the array. As the frames are rendered a line that progressed based on the coordinates is displayed.  The render target is a MFC MDI client window. The render frames are called from a thread of class OpenThreads::Thread<br>
<br>
While trying to debug the issue using logs.  I found that when the numPtsinHandClubPath value goes to 199 it crashes. We can see that the array size is 2000.  Everytime it used to crash after 200 values were updated into the coordinate vector and color vector.<br>
<br>
It has never crashed on two of my machines so I dont have the stack and variable values. Few remote machines it has crashed.<br>
Do let me know if there is any query or clarity required.<br>
... <br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Rakesh<br>
<br>
Code:<br>
<br>
//following variables are defined in COSGViewer<br>
        osg::MatrixTransform* mtClubHandPath;<br>
        osg::ref_ptr<osg::Geode> osgGeodeHandClubPath;<br>
        unsigned int MaxPtsInHandCLubPath;<br>
        osg::ref_ptr<osg::Geometry> geomHandPath;<br>
        osg::ref_ptr<osg::Geometry> geomClubPath;<br>
        osg::ref_ptr<osg::Vec3Array> coordsHandPath;<br>
        osg::ref_ptr<osg::Vec3Array> coordsClubPath;<br>
        osg::ref_ptr<osg::Vec4Array> coloursHandPath;<br>
        osg::ref_ptr<osg::Vec4Array> coloursClubPath;<br>
        osg::ref_ptr<osg::DrawArrays> drawArrayHandPath;<br>
        osg::ref_ptr<osg::DrawArrays> drawArrayClubPath;<br>
<br>
<br>
osg::MatrixTransform* COSGViewer::createHUDClubHdPts(int X0, int Y0, int X1, int Y1, int textYOffset)<br>
{<br>
        mtClubHandPath = new osg::MatrixTransform();<br>
        osg::Matrix m;<br>
        m.makeTranslate(0, 0, 0);<br>
        mtClubHandPath->setMatrix(m);<br>
<br>
        RECT rect;<br>
        ::GetWindowRect(m_hWnd, &rect);<br>
<br>
<br>
        osg::ref_ptr<osg::Geometry> linesGeom = new osg::Geometry();<br>
        osgGeodeHandClubPath = new osg::Geode();<br>
<br>
        osg::ref_ptr<osg::StateSet> stateset = osgGeodeHandClubPath->getOrCreateStateSet();<br>
<br>
        stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);<br>
        stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);<br>
<br>
        osg::ref_ptr<osg::LineWidth> linewidth = new osg::LineWidth();<br>
        linewidth->setWidth(4.0f);<br>
        stateset->setAttributeAndModes(linewidth, osg::StateAttribute::ON);<br>
<br>
        unsigned int n_points = 2000;<br>
        MaxPtsInHandCLubPath = n_points;<br>
        numPtsinHandClubPath = 0;<br>
        geomHandPath = new osg::Geometry();<br>
        geomClubPath = new osg::Geometry();<br>
<br>
        coordsHandPath = new osg::Vec3Array;// (n_points);<br>
        coordsClubPath = new osg::Vec3Array;// (n_points);<br>
        coloursHandPath = new osg::Vec4Array;// (n_points);<br>
        coloursClubPath = new osg::Vec4Array;// (n_points);<br>
<br>
<br>
                for (unsigned int j = 0; j < n_points; ++j) {<br>
<br>
                        coordsHandPath->push_back(osg::Vec3(0, 0, 0));<br>
                        coordsClubPath->push_back(osg::Vec3(0, 0, 0));<br>
                        coloursHandPath->push_back(osg::Vec4(1.0, 0, 0, 1.0));<br>
                        coloursClubPath->push_back(osg::Vec4(0, 0, 1.0, 1.0));<br>
<br>
<br>
                }<br>
<br>
<br>
                geomHandPath->setVertexArray(coordsHandPath);<br>
                geomClubPath->setVertexArray(coordsClubPath);<br>
<br>
                drawArrayHandPath = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);<br>
                //geomHandPath->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, n_points));<br>
                geomHandPath->addPrimitiveSet(drawArrayHandPath);<br>
<br>
                drawArrayClubPath = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP);<br>
                geomClubPath->addPrimitiveSet(drawArrayClubPath);<br>
<br>
<br>
        geomHandPath->setColorArray(coloursHandPath, osg::Array::BIND_PER_VERTEX);<br>
        geomClubPath->setColorArray(coloursClubPath, osg::Array::BIND_PER_VERTEX);<br>
<br>
        geomHandPath->setDataVariance(osg::Object::DYNAMIC);<br>
        geomClubPath->setDataVariance(osg::Object::DYNAMIC);<br>
<br>
        osgGeodeHandClubPath->addDrawable(geomHandPath);<br>
        osgGeodeHandClubPath->addDrawable(geomClubPath);<br>
<br>
        mtClubHandPath->addChild(osgGeodeHandClubPath);<br>
        return mtClubHandPath;<br>
}<br>
<br>
<br>
<br>
void COSGViewer::AddCurPtToHandClubPath(int ccurFr, int cPrevFr)<br>
{<br>
        if (ccurFr != -1)<br>
        {<br>
                if (ccurFr == cPrevFr)<br>
                        return;<br>
        }<br>
<br>
        osg::Vec3Array * lcoordsHandPath = dynamic_cast<osg::Vec3Array*>(geomHandPath->getVertexArray());<br>
        osg::Vec3Array * lcoordsClubPath = dynamic_cast<osg::Vec3Array*>(geomClubPath->getVertexArray());<br>
<br>
        osg::Vec4Array * lcolorHandPath = dynamic_cast<osg::Vec4Array*>(geomHandPath->getColorArray());<br>
        osg::Vec4Array * lcolorClubPath = dynamic_cast<osg::Vec4Array*>(geomClubPath->getColorArray());<br>
<br>
        osg::Vec3 lhandVec;<br>
<br>
        float fps = 240.0f;<br>
<br>
        if (mPolhemus->mnUseG4data == 2)<br>
                fps = 120.0f;<br>
<br>
        if (((fps == 120.0f) && (mPolhemus->m_nActiveHubCount == 2)) || (fps == 240.0f))<br>
        {<br>
                if (osgViewerTrailCalib == FALSE)<br>
                {<br>
                        if ((mRightHandedness == 1) || (mRightHandedness == -1))<br>
                        {<br>
                                lhandVec = vSensorCM[7];<br>
                        }<br>
                        else<br>
                        {<br>
                                lhandVec = vSensorCM[5];<br>
                        }<br>
                }<br>
                else<br>
                {<br>
                        if ((mRightHandedness == 1) || (mRightHandedness == -1))<br>
                        {<br>
                                lhandVec = vSensorCM[5];<br>
                        }<br>
                        else<br>
                        {<br>
                                lhandVec = vSensorCM[7];<br>
                        }<br>
                }<br>
        }<br>
        else<br>
        {<br>
                lhandVec = vVMidHands;<br>
        }<br>
<br>
        (*lcoordsHandPath)[numPtsinHandClubPath] = lhandVec;<br>
        (*lcoordsClubPath)[numPtsinHandClubPath] = vVClub;<br>
<br>
        if (ccurFr == osgAddress)<br>
        {<br>
        }<br>
<br>
<br>
<br>
        if (ccurFr != -1)<br>
        {<br>
                if (ccurFr <= osgTop)<br>
                {<br>
<br>
                        (*lcolorHandPath)[numPtsinHandClubPath] = hdClubPathcrKey[0];<br>
                        (*lcolorClubPath)[numPtsinHandClubPath] = hdClubPathcrKey[3];<br>
                }<br>
                else if ((ccurFr > osgTop) && (ccurFr <= osgImpact))<br>
                {<br>
<br>
                        (*lcolorHandPath)[numPtsinHandClubPath] = hdClubPathcrKey[1];<br>
                        (*lcolorClubPath)[numPtsinHandClubPath] = hdClubPathcrKey[4];<br>
                }<br>
                else if (ccurFr > osgImpact)<br>
                {<br>
<br>
                        (*lcolorHandPath)[numPtsinHandClubPath] = hdClubPathcrKey[2];<br>
                        (*lcolorClubPath)[numPtsinHandClubPath] = hdClubPathcrKey[5];<br>
                }<br>
        }<br>
        else<br>
        {<br>
                (*lcolorHandPath)[numPtsinHandClubPath] = hdClubPathcrKey[0];<br>
                (*lcolorClubPath)[numPtsinHandClubPath] = hdClubPathcrKey[3];<br>
        }<br>
<br>
<br>
        unsigned int lnumEleDisp;<br>
        if (numPtsinHandClubPath > 10)<br>
                lnumEleDisp = numPtsinHandClubPath+1;<br>
        else<br>
                lnumEleDisp = numPtsinHandClubPath+1;<br>
<br>
        lcoordsHandPath->dirty();<br>
        lcoordsClubPath->dirty();<br>
<br>
        drawArrayHandPath->setFirst(0);<br>
        drawArrayHandPath->setCount(lnumEleDisp);<br>
<br>
        drawArrayClubPath->setFirst(0);<br>
        drawArrayClubPath->setCount(lnumEleDisp);<br>
<br>
        geomHandPath->setUseDisplayList(false);<br>
        geomHandPath->dirtyDisplayList();<br>
        geomHandPath->dirtyBound();<br>
<br>
        geomClubPath->setUseDisplayList(false);<br>
        geomClubPath->dirtyDisplayList();<br>
        geomClubPath->dirtyBound();<br>
<br>
        if (numPtsinHandClubPath == 200)<br>
        {<br>
                LOGD.LOGRP(FL, "State2");<br>
        }<br>
<br>
        numPtsinHandClubPath++;<br>
<br>
        if (numPtsinHandClubPath == MaxPtsInHandCLubPath)<br>
        {<br>
                ClearAnimHandClubPath(0, 0);<br>
        }<br>
<br>
        if (numPtsinHandClubPath == 200)<br>
        {<br>
                LOGD.LOGRP(FL, "State3");<br>
        }<br>
<br>
}<br>
<br>
<br>
<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=76790#76790" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=76790#76790</a><br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">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></div>