Google

memory leak

Discussion relating to the Caelum sky rendering plugin

Moderators: OGRE Team, Caelum Moderators

memory leak

Postby mickey » Fri Jan 30, 2009 7:15 am

Hi

This is all my code:

Caelum::CaelumSystem::CaelumComponent componentMask;
componentMask = static_cast<Caelum::CaelumSystem::CaelumComponent> (Caelum::CaelumSystem::CAELUM_COMPONENT_CLOUDS);

gCaelumSystem = new Caelum::CaelumSystem (Root::getSingletonPtr(), mSceneMgr, componentMask);

And on my destructor:

if (gCaelumSystem)
{
gCaelumSystem->shutdown (false);
gCaelumSystem = 0;
}

And caelum will leak a lot of memory.

Any idea?
mickey
 
Posts: 48
Joined: Mon Dec 15, 2008 2:47 pm

Re: memory leak

Postby cdleonard » Fri Jan 30, 2009 9:27 am

You're doing it wrong; see http://caelum.sourceforge.net/doc/0.4.0 ... 501430c61a for the shutdown method. You already said in another topic you don't add CaelumSystem as a FrameListener; so leaks are to be expected. This is by design.

You should just call "delete gCaelumSystem" in shutdown code; that should work in your case. Or you can just hold CaelumSystem inside an auto_ptr for extra safety. I personally try to avoid all manual deletions when possible.
User avatar
cdleonard
 
Posts: 98
Joined: Wed May 30, 2007 12:56 pm
Location: Bucharest, Romania

Re: memory leak

Postby mickey » Mon Feb 02, 2009 10:38 am

Hi cdleonard

Thanks for your reply.

I did what you said - modified my destructor code:

if (gCaelumSystem)
{
delete gCaelumSystem;
gCaelumSystem = NULL;
}

I also tried calling shutdown(true) instead of false earlier. Didn't help.

I still get memory leak?
mickey
 
Posts: 48
Joined: Mon Dec 15, 2008 2:47 pm

Re: memory leak

Postby cdleonard » Tue Feb 03, 2009 6:54 pm

I'd don't know then; it should clean up properly. What makes you sure that Caelum leaks memory?
User avatar
cdleonard
 
Posts: 98
Joined: Wed May 30, 2007 12:56 pm
Location: Bucharest, Romania

Re: memory leak

Postby mickey » Wed Feb 04, 2009 6:33 am

Hi cdleonard

I have eveything enabled but caelum and when i quit my app, there's no memory leak. whenever i add caelum to my game and shuts down, i get memory leak report.

There's actually one more issue but i was hoping this first issue was solve first. The other issue is i get a crash when deleting the caelum object if i create a 2nd clour layer:

Caelum::FlatCloudLayer* layer = gCaelumSystem->getCloudSystem ()->createLayerAtHeight (1800.f);
layer->setFadeDistances( farClip * 0.8f, farClip );
layer->setCloudCover (0.7f);
layer->_ensureGeometry();
gCaelumSystem->getCloudSystem()->addLayer(layer);

On the call to delete gCaelumSystem on my ExampleApplication destructor, my application will crash. I also tried deleting the 2nd cloud layer manually prior to delete gCaelumSystem, didn't work.

I could try somethings for you if you want, just tell me which ones so we can nail down the problem.
mickey
 
Posts: 48
Joined: Mon Dec 15, 2008 2:47 pm

Re: memory leak

Postby cdleonard » Wed Feb 04, 2009 12:00 pm

The createLayerAtHeight adds the layer before it returns; you don't need to do addLayer. When CaelumSystem shuts down it deletes all added layers and you get a double free which causes a crash.
User avatar
cdleonard
 
Posts: 98
Joined: Wed May 30, 2007 12:56 pm
Location: Bucharest, Romania


Return to Caelum

Who is online

Users browsing this forum: No registered users and 1 guest

cron