[SOLVED] resource leaks

scrawl

30-04-2012 20:17:50

I'm doing tooltips that show info about selected items in the game with MyGUI. Because the tooltips can contain a variety of information (with different types and counts of sub-widgets, depending on the item) I have to update these widgets (create and destroy) every frame. Basically, I was doing it like this:


void ToolTips::onFrame(float frameDuration)
{
for (size_t i=0; i<mDynamicToolTipBox->getChildCount(); ++i)
{
MyGUI::Gui::getInstance().destroyWidget(mDynamicToolTipBox->getChildAt(i));
}

/* Create new widgets as children of mDynamicToolTipBox*/
.....
}


However, I noticed that after looking at an object and displaying it's tooltip, the framerate drops quite rapidly. After a few seconds I'm down to 10 fps from the initial 200 fps. So, I played around a little and now use this instead:


void ToolTips::onFrame(float frameDuration)
{
MyGUI::Gui::getInstance().destroyWidget(mDynamicToolTipBox);

mDynamicToolTipBox = mMainWidget->createWidget<Widget>("HUD_Box",
IntCoord(0, 0, mMainWidget->getCoord().width, mMainWidget->getCoord().height),
Align::Stretch, "DynamicToolTipBox");

/* Create new widgets as children of mDynamicToolTipBox */
}

With the second solution I have no FPS drop at all. Is there any reason why the first solution apparently causes MyGUI to leak resources, and the second one not?

Altren

01-05-2012 13:20:24

You are deleting only half of child widgets, because when you call destroyWidget getChildCount changes, since widget now have less childs. Result of such operation is that you destroy every even child. You should use something like
while (mDynamicToolTipBox->getChildCount())
{
MyGUI::Gui::getInstance().destroyWidget(mDynamicToolTipBox->getChildAt(i));
}

scrawl

01-05-2012 19:12:37

Oops, my bad :lol: