PixelBufferWin32 memory leak and resize functionality
Hi osg-users,
In the application I'am working on we use PixelBufferWin32. I found there was a large memory leak and noticed incorrect shader result after destroying and creating a new pbuffer-enabled viewer.
( I adapted the pbuffertest code posted a while ago to create and destroy multiple pbuffers to see that this caused the leakage) :
traits->pbuffer = true //leaks
v.s.
traits->pbuffer = false //doesn't leak
After some experimenting I decided to reuse the existing pbuffer to solve the problems. However this did not work if the pbuffer needed a different size. So I created a resize function in the
PixelBufferWin32 class. This function does something like this (short version):
//create new pbuffer
newhwnd =wgle->wglCreatePbufferARB(_hdc, _format, width, height, &bAttribList[0]);
newhdc = wgle->wglGetPbufferDCARB(newhwnd);
newhglrc = wglCreateContext(newhdc);
// delete the old context and pbuffer
wglMakeCurrent(_hdc,0);
if ( !wglDeleteContext(_hglrc) ) {}
if ( !wgle->wglReleasePbufferDCARB(_hwnd, _hdc) ) {}
if ( !wgle->wglDestroyPbufferARB(_hwnd) ) {}
_hwnd = newhwnd;
_hdc = newhdc;
_hglrc = newhglrc;
This solved the problems, now I could reuse and resize pbuffers. The difference with this function and creating and destroying the entire PixelBufferWin32 is that there is no TempWindow involved.
It is the TempWindow class that was causing the memory leak. There is a comment in the code of this class:
PixelBufferWin32.cpp:
319: // mew 2005-05-09 commented out due to crashes.
320: // possible causes are unsafe destructor ordering, or context already
321: // deleted by window deletion; see:
323: //wglDeleteContext(_context);
324: _context = 0;
after uncommenting the wglDeleteContext(_context) call the memory leak was gone.
I could not read the original post and now I am not sure how to procede. If we want a resize function in the PixelBufferWin32 class I can submit this? Can the wglDeleteContext(_context)
be uncommented without causing the original crashes? Other suggestions?
Thanks!
René
<div>
<div>Hi osg-users,</div>
<div><br></div>
<div>In the application I'am working on we use PixelBufferWin32. I found there was a large memory leak and noticed incorrect shader result after destroying and creating a new pbuffer-enabled viewer.</div>
<div>( I adapted the pbuffertest code posted a while ago to create and destroy multiple pbuffers to see that this caused the leakage) :</div>
<div><br></div>
<div>traits->pbuffer = true //leaks</div>
<div>v.s.</div>
<div>
traits->pbuffer = false //doesn't leak</div>
<div><br></div>
<div>After some experimenting I decided to reuse the existing pbuffer to solve the problems. However this did not work if the pbuffer needed a different size. So I created a resize function in the</div>
<div>PixelBufferWin32 class. This function does something like this (short version):</div>
<div><br></div>
<div> //create new pbuffer</div>
<div>
<div> newhwnd =wgle->wglCreatePbufferARB(_hdc, _format, width, height, &bAttribList[0]);</div>
<div> newhdc = wgle->wglGetPbufferDCARB(newhwnd);</div>
<div> newhglrc = wglCreateContext(newhdc);</div>
<div> // delete the old context and pbuffer<span class="Apple-tab-span"> </span>
</div>
<div> wglMakeCurrent(_hdc,0);</div>
<div> if ( !wglDeleteContext(_hglrc) ) {}</div>
<div> if ( !wgle->wglReleasePbufferDCARB(_hwnd, _hdc) ) {}</div>
<div> if ( !wgle->wglDestroyPbufferARB(_hwnd) ) {}</div>
<div>
_hwnd = newhwnd;</div>
<div> _hdc = newhdc;</div>
<div> _hglrc = newhglrc;</div>
</div>
<div><br></div>
<div>This solved the problems, now I could reuse and resize pbuffers. The difference with this function and creating and destroying the entire PixelBufferWin32 is that there is no TempWindow involved.</div>
<div>It is the TempWindow class that was causing the memory leak. There is a comment in the code of this class:</div>
<div><br></div>
<div>PixelBufferWin32.cpp:</div>
<div><br></div>
<div>
<div>319: // mew 2005-05-09 commented out due to crashes.</div>
<div>320: // possible causes are unsafe destructor ordering, or context already</div>
<div>321: // deleted by window deletion; see:</div>
<div>322: // <a href="http://openscenegraph.org/pipermail/osg-users/2005-May/052753.html">http://openscenegraph.org/pipermail/osg-users/2005-May/052753.html</a>
</div>
<div>323: //wglDeleteContext(_context);</div>
<div>324: _context = 0;</div>
</div>
<div><br></div>
<div>after uncommenting the wglDeleteContext(_context) call the memory leak was gone.</div>
<div>I could not read the original post and now I am not sure how to procede. If we want a resize function in the PixelBufferWin32 class I can submit this? Can the wglDeleteContext(_context) </div>
<div>be uncommented without causing the original crashes? Other suggestions?</div>
<div><br></div>
<div>Thanks!</div>
<div><br></div>
<div>René</div>
</div>