diff --git a/src/race/grand_prix_manager.cpp b/src/race/grand_prix_manager.cpp index 48b02046e..d0eb5dfef 100644 --- a/src/race/grand_prix_manager.cpp +++ b/src/race/grand_prix_manager.cpp @@ -27,10 +27,30 @@ #include #include +#include // remove later + GrandPrixManager *grand_prix_manager = NULL; const char* GrandPrixManager::SUFFIX = ".grandprix"; +// ---------------------------------------------------------------------------- +GrandPrixManager::GrandPrixManager() +{ + m_random_gp = NULL; // better do it explicitly and avoid weird stuff + loadFiles(); +} + +// ---------------------------------------------------------------------------- +GrandPrixManager::~GrandPrixManager() +{ + for(unsigned int i=0; igetId() == s) diff --git a/src/race/grand_prix_manager.hpp b/src/race/grand_prix_manager.hpp index c8510bf3a..314ddcc59 100644 --- a/src/race/grand_prix_manager.hpp +++ b/src/race/grand_prix_manager.hpp @@ -47,6 +47,10 @@ private: bool existsName(const irr::core::stringw& name) const; public: + /** saved here by a random GP dialog to avoid dangling pinters or + * memory leaks */ + GrandPrixData* m_random_gp; + GrandPrixManager(); ~GrandPrixManager(); void reload(); diff --git a/src/states_screens/dialogs/random_gp_dialog.cpp b/src/states_screens/dialogs/random_gp_dialog.cpp index afa4aebc4..412d850cf 100644 --- a/src/states_screens/dialogs/random_gp_dialog.cpp +++ b/src/states_screens/dialogs/random_gp_dialog.cpp @@ -45,7 +45,14 @@ RandomGPInfoDialog::RandomGPInfoDialog() m_over_body = m_area.getHeight()/7 + SPINNER_HEIGHT + 10; // 10px space m_lower_bound = m_area.getHeight()*6/7; + // The GP manager is be used to make the GP live longer than this dialog + if (grand_prix_manager->m_random_gp) + { + delete grand_prix_manager->m_random_gp; + grand_prix_manager->m_random_gp = NULL; + } m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; addTitle(); addSpinners(); @@ -91,9 +98,8 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( if (eventSource == "start") { // Save the gp since dismiss deletes it otherwise - GrandPrixData buff = *m_gp; ModalDialog::dismiss(); - race_manager->startGP(&buff, false, false); + race_manager->startGP(m_gp, false, false); return GUIEngine::EVENT_BLOCK; } else if (eventSource == "Number of tracks") @@ -132,10 +138,10 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent( void RandomGPInfoDialog::updateGP() { - if (m_gp != NULL) - delete m_gp; + delete m_gp; m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse); + grand_prix_manager->m_random_gp = m_gp; addTracks(); } diff --git a/src/states_screens/dialogs/random_gp_dialog.hpp b/src/states_screens/dialogs/random_gp_dialog.hpp index ee66a8f30..587bd06cf 100644 --- a/src/states_screens/dialogs/random_gp_dialog.hpp +++ b/src/states_screens/dialogs/random_gp_dialog.hpp @@ -33,7 +33,6 @@ public: static const int SPINNER_HEIGHT = 40; RandomGPInfoDialog(); - ~RandomGPInfoDialog() { delete m_gp; } /** Adds a SpinnerWidgets to choose the track groups and one to choose the * number of tracks */