improve a lot leaks of CGUIEditBox objects

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9990 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-10-16 00:00:57 +00:00
parent 3707765721
commit a8dfd29f65
6 changed files with 30 additions and 38 deletions

View File

@@ -253,3 +253,25 @@ Widget* AbstractTopLevelContainer::getLastWidget(
} // getLastWidget
// ----------------------------------------------------------------------------
/**
* Called when screen is removed. This means all irrlicht widgets this object has pointers
* to are now gone. Set all references to NULL to avoid problems.
*/
void AbstractTopLevelContainer::elementsWereDeleted(PtrVector<Widget>* within_vector)
{
if (within_vector == NULL) within_vector = &m_widgets;
const unsigned short widgets_amount = within_vector->size();
for (int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
widget.elementRemoved();
if (widget.m_children.size() > 0)
{
elementsWereDeleted( &(widget.m_children) );
}
}
} // elementsWereDeleted

View File

@@ -97,6 +97,8 @@ namespace GUIEngine
Widget* getFirstWidget(PtrVector<Widget>* within_vector=NULL);
Widget* getLastWidget(PtrVector<Widget>* within_vector=NULL);
void elementsWereDeleted(PtrVector<Widget>* within_vector = NULL);
bool isMyChild(Widget* widget) const;
}; // AbstractTopLevelContainer

View File

@@ -136,6 +136,12 @@ ModalDialog::~ModalDialog()
else irr_driver->hidePointer();
input_manager->setMode(m_previous_mode);
// it's generally not necessay to do that because references
// to the deleted widgets will be gone, but some widgets
// may want to perform additional cleanup at this time
elementsWereDeleted();
}
// ----------------------------------------------------------------------------

View File

@@ -175,31 +175,6 @@ void Screen::addWidgets()
// -----------------------------------------------------------------------------
/**
* Called when screen is removed. This means all irrlicht widgets this object has pointers
* to are now gone. Set all references to NULL to avoid problems.
*/
void Screen::elementsWereDeleted(PtrVector<Widget>* within_vector)
{
assert(m_magic_number == 0xCAFEC001);
if (within_vector == NULL) within_vector = &m_widgets;
const unsigned short widgets_amount = within_vector->size();
for (int n=0; n<widgets_amount; n++)
{
Widget& widget = (*within_vector)[n];
widget.elementRemoved();
if (widget.m_children.size() > 0)
{
elementsWereDeleted( &(widget.m_children) );
}
}
} // elementsWereDeleted
// -----------------------------------------------------------------------------
void Screen::manualAddWidget(Widget* w)
{
assert(m_magic_number == 0xCAFEC001);

View File

@@ -164,12 +164,6 @@ namespace GUIEngine
/** \return the name of this menu (which is the name of the file) */
const std::string& getName() const { return m_filename; }
/**
* \brief invoked when irrlicht widgets added to the screen have been deleted
* so that we can drop any pointer to them we had (they are now dangling pointers)
*/
void elementsWereDeleted(PtrVector<Widget>* within_vector = NULL);
/** Next time this menu needs to be shown, don't use cached values, re-calculate everything.
(useful e.g. on reschange, when sizes have changed and must be re-calculated) */
virtual void unload();

View File

@@ -145,13 +145,6 @@ void TextBoxWidget::unfocused(const int playerID)
assert(playerID == 0); // No support for multiple players in text areas!
setWithinATextBox(false);
// special case : to work, the text box must receive "irrLicht focus", STK focus is not enough
// below is a cheap way to unset the irrLicht focus from the widget (nope, 'removeFocus' from
// IGUIEnv doesn't work reliably, not sure why)
// currently, text boxes are only used in modal dialogs, so I shift the focus to the dialog
assert( ModalDialog::isADialogActive() );
GUIEngine::getGUIEnv()->setFocus( ModalDialog::getCurrent()->getIrrlichtElement() );
}
// -----------------------------------------------------------------------------