PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

memory leak in pocketfrog 0_8_1

I have found leaks in rasterizer in PF.
m_alphaRaster created in SetBlending(uint8_t alpha) and m_genericRaster created in SetPixelShader( PixelShader* shader ), but none of them is deleted after...

To correct this i've changed code in rasterizer.h:
Code:

// from
Internal::AlphaRaster2D* m_alphaRaster;
Internal::GenericRaster2D* m_genericRaster;
// to
scoped_ptr<Internal::AlphaRaster2D> m_alphaRaster;
scoped_ptr<Internal::GenericRaster2D> m_genericRaster;
,
Code:

void Rasterizer::SetPixelShader( PixelShader* shader )
{
// old code
}
//to
void Rasterizer::SetPixelShader( PixelShader* shader )
{
if (m_genericRaster.get() == 0)
m_genericRaster.reset(new Internal::GenericRaster2D( shader ));
else
m_genericRaster->SetPixelShader( shader );

m_raster = m_genericRaster.get();
}

and
Code:

void Rasterizer::SetBlending( uint8_t alpha )
{
// old code
}
// to

void Rasterizer::SetBlending( uint8_t alpha )
{
// The last two bits of alpha are not significant
if ( (alpha | 0x03) == 0xFF )
{
// Completely opaque
SetDefaultShader();
}
else
{
if (m_alphaRaster.get() == 0)
m_alphaRaster.reset(new Internal::AlphaRaster2D( alpha ));
else
m_alphaRaster->SetAlpha( alpha );

m_raster = m_alphaRaster.get();
}
}



All.
Great! dyn, I'll check this and if everything is fine, I'll add it to the next PF_0_8_1_bugfix, OK?

If it is OK for you that I add your code to the bugfix, can you please post here or PM me this code without boost::scoped_ptr, so the others could use next version of bugfix without installing boost. I can change it myself,but it's better you do - I'm not so sure about my knowledge about pointers ;)

Thank you
BIGBEN, check out PocketFrog8\source\foreign\boost. The source of ancient knowledge lies beneath :).
it's best to take scoped_ptr.hpp from 0.7 When we found this leak i showed Dyn how it's done in 0.7 and he adjusted he's code. Its realy looks bad without failsafe ptr.
jaguard wrote:BIGBEN, check out PocketFrog8\source\foreign\boost. The source of ancient knowledge lies beneath :).


thanks :P

OK, Dyn, can I include your code "as is" in my next bugfix? Or scoped_ptr or auto_ptr or any other that works best, so I'll include it in the bugfix ;)
BIGBEN":2gpkpeo5]

In what a question? Certainly, you can. It would be fine. 8)
BIGBEN, take a time to look in code of scoped_ptr. Is's very easy and useful. :D


p.s. Русский топик. :)
Under what situation does the leak occur? I'm using a huge amount of blending, but no custom shaders, and I have not seen any indication of a leak.

I had leaks a while back because I was not deleting the rasterizers I created.
Thats exactly what happening there. No one cares to delete rasterizers :)