fix crash due to a dangling pointer
This commit is contained in:
parent
6bf1a33ddc
commit
6521e3d496
@ -27,10 +27,30 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include <iostream> // 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; i<m_gp_data.size(); i++)
|
||||
{
|
||||
delete m_gp_data[i];
|
||||
}
|
||||
|
||||
delete m_random_gp;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixManager::loadFiles()
|
||||
{
|
||||
@ -130,21 +150,6 @@ bool GrandPrixManager::existsName(const irr::core::stringw& name) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixManager::GrandPrixManager()
|
||||
{
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixManager::~GrandPrixManager()
|
||||
{
|
||||
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
||||
{
|
||||
delete m_gp_data[i];
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
||||
{
|
||||
@ -154,6 +159,10 @@ GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
|
||||
// ----------------------------------------------------------------------------
|
||||
GrandPrixData* GrandPrixManager::editGrandPrix(const std::string& s) const
|
||||
{
|
||||
std::cout << s << std::endl;
|
||||
if (s == "random")
|
||||
return m_random_gp;
|
||||
|
||||
for(unsigned int i=0; i<m_gp_data.size(); i++)
|
||||
{
|
||||
if(m_gp_data[i]->getId() == s)
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user