Defer closing player name dialog to avoid potential memory corruption/crashes
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11163 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
66da1d408b
commit
c197356f86
@ -39,6 +39,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener,
|
||||
ModalDialog(w, h)
|
||||
{
|
||||
m_listener = listener;
|
||||
m_self_destroy = false;
|
||||
loadFromFile("enter_player_name_dialog.stkgui");
|
||||
|
||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||
@ -128,6 +129,27 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
|
||||
UserConfigParams::m_all_players.push_back( new PlayerProfile(playerName) );
|
||||
|
||||
// It's unsafe to delete from inside the event handler so we do it later
|
||||
m_self_destroy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||
label->setText(_("Cannot add a player with this name."), false);
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void EnterPlayerNameDialog::onUpdate(float dt)
|
||||
{
|
||||
// It's unsafe to delete from inside the event handler so we do it later
|
||||
if (m_self_destroy)
|
||||
{
|
||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||
stringw playerName = textCtrl->getText();
|
||||
|
||||
// irrLicht is too stupid to remove focus from deleted widgets
|
||||
// so do it by hand
|
||||
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
|
||||
@ -142,14 +164,4 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
||||
|
||||
if (listener != NULL) listener->onNewPlayerWithName( playerName );
|
||||
}
|
||||
else
|
||||
{
|
||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
||||
label->setText(_("Cannot add a player with this name."), false);
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
private:
|
||||
|
||||
INewPlayerListener* m_listener;
|
||||
bool m_self_destroy;
|
||||
|
||||
public:
|
||||
|
||||
@ -63,6 +64,7 @@ public:
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
||||
virtual void onUpdate(float dt);
|
||||
//virtual void onTextUpdated();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user