<div dir="ltr">Hi Robert,<div><br></div><div>I am using code extracted from the osgscreencapture example to generate small thumbnails of loaded shapes.</div><div>It all work is very nicely except that it is leaking memory on each usage.  I have commented out our code and based on that and a few other tests I am fairly convinced that the leak is the pixel buffer (GraphicsContext) itself.</div><div><br></div><div><br></div><div><div class="prettyprint" style="background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class="prettyprint"><div class="subprettyprint"><font color="#666600"><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">ref_ptr</span><span style="color: #660;" class="styled-by-prettify"><</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">GraphicsContext</span><span style="color: #660;" class="styled-by-prettify">></span></font></div></code><div class="subprettyprint"><font color="#666600" face="monospace">createPixelBuffer(int aSize, int aNumSamples)</font></div><div class="subprettyprint"><font color="#666600" face="monospace">{</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->x                                         = 0;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->y                                         = 0;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->width                                     = aSize;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->height                                    = aSize;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->red                                       = 8;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->green                                     = 8;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->blue                                      = 8;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->alpha                                     = 8;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->windowDecoration                          = false;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->pbuffer                                   = true;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->doubleBuffer                              = true;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->sharedContext                             = 0;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->readDISPLAY();</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    traits->setUndefinedScreenDetailsToDefaultScreen();</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    if (aNumSamples != 0)</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    {</font></div><div class="subprettyprint"><font color="#666600" face="monospace">        traits->sampleBuffers = 1;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">        traits->samples       = aNumSamples;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    }</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    return osg::GraphicsContext::createGraphicsContext(traits.get());</font></div><div class="subprettyprint"><font color="#666600" face="monospace">}</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">bool</font></div><div class="subprettyprint"><font color="#666600" face="monospace">generateThumbnail(const std::string & aFilePath,</font></div><div class="subprettyprint"><font color="#666600" face="monospace">                  const std::string & aThumbnailPath,</font></div><div class="subprettyprint"><font color="#666600" face="monospace">                  const std::string & aResourcesPath,</font></div><div class="subprettyprint"><font color="#666600" face="monospace">                  int                 aSize,</font></div><div class="subprettyprint"><font color="#666600" face="monospace">                  bool                aTopDownView)</font></div><div class="subprettyprint"><font color="#666600" face="monospace">{</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    auto pixelBuffer = createPixelBuffer(aSize, 8);</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    if (!pixelBuffer)</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    {</font></div><div class="subprettyprint"><font color="#666600" face="monospace">        pixelBuffer = createPixelBuffer(aSize, 0);</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    }</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">//    const auto shape = loadShapeOrError(aFilePath);</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    auto              camera = viewer->getCamera();</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    camera->setGraphicsContext(pixelBuffer.get());</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    camera->setViewport(new osg::Viewport(0, 0, aSize, aSize));</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    camera->setDrawBuffer(GL_BACK);</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    camera->setReadBuffer(GL_BACK);</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">//    setupShapeViewer(viewer, shape.get(), aResourcesPath, aTopDownView);</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">//    osg::ref_ptr<ImageGrabber> grabber = new ImageGrabber(aThumbnailPath);</font></div><div class="subprettyprint"><font color="#666600" face="monospace">//    viewer.getCamera()->setPostDrawCallback(grabber.get());</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    viewer->realize();</font></div><div class="subprettyprint"><font color="#666600" face="monospace">    viewer->frame();</font></div><div class="subprettyprint"><font color="#666600" face="monospace"><br></font></div><div class="subprettyprint"><font color="#666600" face="monospace">    return true;</font></div><div class="subprettyprint"><font color="#666600" face="monospace">};</font></div><div><br></div></div><br>If I call the above code repeatedly then it leaks and I cannot understand why since everything is in osg:ref_ptr<>. </div><div>The Viewer was a concrete instance originally but that makes no difference.</div><div>I have also tried using a slave camera as in the original example.</div><div>I have a nasty workaround of extracting a shared pixel buffer and re-using it - but ideally this code would be called using std::async, to have multiple thumbnails generated in parallel, so that is going to be tricky.</div><div><br></div><div>Kinda hoping you can point to my stupid mistake in how I am using osg ;)</div><div><br></div><div>Thanks,</div><div><br></div><div>Brian</div><div><br></div><div><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/acdd2682-5b66-4064-aed1-66d2e5c9e3d5o%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/acdd2682-5b66-4064-aed1-66d2e5c9e3d5o%40googlegroups.com</a>.<br />