Fixed crash when deleting keyboard config + added assertions to detect more possible bugs in the future

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6366 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-10-27 23:13:18 +00:00
parent 9fa58cd856
commit 82214d0622
4 changed files with 31 additions and 5 deletions

View File

@@ -21,6 +21,7 @@
#include <vector>
#include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/screen.hpp"
#include "input/device_manager.hpp"
@@ -43,6 +44,8 @@ AbstractStateManager::AbstractStateManager()
void AbstractStateManager::enterGameState()
{
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
if (getCurrentScreen() != NULL) getCurrentScreen()->tearDown();
m_menu_stack.clear();
m_menu_stack.push_back(RACE_STATE_NAME);
@@ -81,6 +84,8 @@ void AbstractStateManager::pushMenu(std::string name)
// currently, only a single in-game menu is supported
assert(m_game_mode != INGAME_MENU);
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0 && m_game_mode != GAME) getCurrentScreen()->tearDown();
@@ -103,6 +108,8 @@ void AbstractStateManager::pushMenu(std::string name)
void AbstractStateManager::pushScreen(Screen* screen)
{
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
if (!screen->isLoaded()) screen->loadFromFile();
pushMenu(screen->getName());
screen->init();
@@ -115,6 +122,7 @@ void AbstractStateManager::pushScreen(Screen* screen)
void AbstractStateManager::replaceTopMostScreen(Screen* screen)
{
assert(m_game_mode != GAME);
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
if (!screen->isLoaded()) screen->loadFromFile();
std::string name = screen->getName();
@@ -138,6 +146,7 @@ void AbstractStateManager::replaceTopMostScreen(Screen* screen)
void AbstractStateManager::reshowTopMostMenu()
{
assert(m_game_mode != GAME);
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
// Send tear-down event to previous menu
if (m_menu_stack.size() > 0)
@@ -196,6 +205,8 @@ void AbstractStateManager::popMenu()
void AbstractStateManager::resetAndGoToScreen(Screen* screen)
{
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
std::string name = screen->getName();
if (m_game_mode != GAME) getCurrentScreen()->tearDown();
@@ -216,6 +227,7 @@ void AbstractStateManager::resetAndSetStack(Screen* screens[])
{
assert(screens != NULL);
assert(screens[0] != NULL);
assert(!ModalDialog::isADialogActive()); // you need to close any dialog before calling this
if (m_game_mode != GAME) getCurrentScreen()->tearDown();
m_menu_stack.clear();

View File

@@ -50,7 +50,7 @@ GUIEngine::EventPropagation ConfirmDialog::processEvent(const std::string& event
if (eventSource == "cancel")
{
ModalDialog::dismiss();
//ModalDialog::dismiss();
m_listener->onCancel();
@@ -58,7 +58,7 @@ GUIEngine::EventPropagation ConfirmDialog::processEvent(const std::string& event
}
else if (eventSource == "confirm")
{
ModalDialog::dismiss();
//ModalDialog::dismiss();
m_listener->onConfirm();
@@ -67,3 +67,10 @@ GUIEngine::EventPropagation ConfirmDialog::processEvent(const std::string& event
return GUIEngine::EVENT_LET;
}
// ------------------------------------------------------------------------------------------------------
void ConfirmDialog::IConfirmDialogListener::onCancel()
{
ModalDialog::dismiss();
}

View File

@@ -40,11 +40,17 @@ public:
IConfirmDialogListener() {}
virtual ~IConfirmDialogListener() {}
/** \brief Implement to be notified of dialog confirmed */
/** \brief Implement to be notified of dialog confirmed.
* \note The dialog is not closed automatically, close it in the callback if this
* behavior is desired.
*/
virtual void onConfirm() = 0;
/** \brief Implement to be notified of dialog cancelled */
virtual void onCancel() {}
/** \brief Implement to be notified of dialog cancelled.
* \note The default implementation is to close the modal dialog, but you may override
* this method to change the behavior.
*/
virtual void onCancel();
};
private:

View File

@@ -418,6 +418,7 @@ void OptionsScreenInput2::onConfirm()
assert(success);
m_config = NULL;
input_manager->getDeviceList()->serialize();
ModalDialog::dismiss();
StateManager::get()->replaceTopMostScreen(OptionsScreenInput::getInstance());
}