Try to convert m_gp from a GPData pointer to a GP object, compiles, but

crashes.
This commit is contained in:
hiker 2014-07-14 23:08:46 +10:00
parent f24a000f78
commit ab57903f9f
6 changed files with 37 additions and 35 deletions

View File

@ -49,7 +49,7 @@ GrandPrixData::GrandPrixData(const std::string& filename)
// ----------------------------------------------------------------------------
GrandPrixData::GrandPrixData(const unsigned int number_of_tracks,
const std::string& track_group,
const RandomGPInfoDialog::REVERSED use_reverse)
const GrandPrixData::GP_Reversed use_reverse)
{
m_filename = "Random GP - Not loaded from a file!";
m_id = "random";
@ -118,13 +118,13 @@ void GrandPrixData::changeTrackNumber(const unsigned int number_of_tracks,
// ----------------------------------------------------------------------------
void GrandPrixData::changeReverse(const RandomGPInfoDialog::REVERSED use_reverse)
void GrandPrixData::changeReverse(const GrandPrixData::GP_Reversed use_reverse)
{
for (unsigned int i = 0; i < m_tracks.size(); i++)
{
if (use_reverse == RandomGPInfoDialog::NO_REVERSE)
if (use_reverse == NO_REVERSE)
m_reversed[i] = false;
else if (use_reverse == RandomGPInfoDialog::MIXED)
else if (use_reverse == MIXED)
if (track_manager->getTrack(m_tracks[i])->reverseAvailable())
m_reversed[i] = (rand() % 2 != 0);
else

View File

@ -24,7 +24,6 @@
#include <string>
#include <vector>
#include "states_screens/dialogs/random_gp_dialog.hpp"
#include "utils/translation.hpp"
using irr::core::stringw;
@ -69,6 +68,14 @@ private:
*/
bool isTrackAvailable(const std::string &id, bool includeLocked) const;
public:
enum GP_Reversed
{
NO_REVERSE = 0,
ALL_REVERSE = 1,
MIXED = 2
};
public:
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
# pragma warning(disable:4290)
@ -80,10 +87,10 @@ public:
/** Creates a new random GP */
GrandPrixData(const unsigned int number_of_tracks,
const std::string& track_group,
const RandomGPInfoDialog::REVERSED use_reverse);
const GP_Reversed use_reverse);
void changeTrackNumber(const unsigned int number_of_tracks,
const std::string& track_group);
void changeReverse(const RandomGPInfoDialog::REVERSED use_reverse);
void changeReverse(const GP_Reversed use_reverse);
// Methods for the GP editor
void setId(const std::string& id);

View File

@ -53,8 +53,8 @@ GPInfoDialog::GPInfoDialog(const std::string& gp_ident)
doInit();
m_curr_time = 0.0f;
m_gp = grand_prix_manager->getGrandPrix(gp_ident);
m_gp->checkConsistency();
m_gp = *grand_prix_manager->getGrandPrix(gp_ident);
m_gp.checkConsistency();
m_under_title = m_area.getHeight()/7;
m_over_body = m_area.getHeight()/7;
@ -72,7 +72,7 @@ GPInfoDialog::~GPInfoDialog()
{
GUIEngine::Screen* curr_screen = GUIEngine::getCurrentScreen();
if (curr_screen->getName() == "tracks.stkgui")
static_cast<TracksScreen*>(curr_screen)->setFocusOnGP(m_gp->getId());
static_cast<TracksScreen*>(curr_screen)->setFocusOnGP(m_gp.getId());
}
// ----------------------------------------------------------------------------
@ -81,7 +81,7 @@ void GPInfoDialog::addTitle()
{
core::rect< s32 > area_top(0, 0, m_area.getWidth(), m_under_title);
IGUIStaticText* title = GUIEngine::getGUIEnv()->addStaticText(
translations->fribidize(m_gp->getName()),
translations->fribidize(m_gp.getName()),
area_top, false, true, // border, word wrap
m_irrlicht_window);
title->setTabStop(false);
@ -92,7 +92,7 @@ void GPInfoDialog::addTitle()
void GPInfoDialog::addTracks()
{
const std::vector<std::string> tracks = m_gp->getTrackNames();
const std::vector<std::string> tracks = m_gp.getTrackNames();
const unsigned int track_amount = tracks.size();
int height_of_one_line = std::min((m_lower_bound - m_over_body)/(track_amount+1),
@ -185,7 +185,7 @@ void GPInfoDialog::addScreenshot()
m_screenshot_widget->m_h = m_area.getWidth()*3/8; // *(3/4)*(1/2)
}
Track* track = track_manager->getTrack(m_gp->getTrackNames()[0]);
Track* track = track_manager->getTrack(m_gp.getTrackNames()[0]);
m_screenshot_widget->m_properties[GUIEngine::PROP_ICON] = (track->getScreenshotFile().c_str());
m_screenshot_widget->setParent(m_irrlicht_window);
m_screenshot_widget->add();
@ -203,7 +203,7 @@ void GPInfoDialog::addButtons()
SavedGrandPrix* saved_gp = SavedGrandPrix::getSavedGP( StateManager::get()
->getActivePlayerProfile(0)
->getUniqueID(),
m_gp->getId(),
m_gp.getId(),
race_manager->getDifficulty(),
race_manager->getNumberOfKarts(),
race_manager->getNumLocalPlayers());
@ -250,7 +250,7 @@ void GPInfoDialog::addButtons()
void GPInfoDialog::onEnterPressedInternal()
{
// Save the GP id because dismiss() will destroy this instance
std::string gp_id = m_gp->getId();
std::string gp_id = m_gp.getId();
ModalDialog::dismiss();
// Disable accidentally unlocking of a challenge
PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
@ -264,7 +264,7 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS
if (eventSource == "start" || eventSource == "continue")
{
// Save GP identifier, since dismiss will delete this object.
std::string gp_id = m_gp->getId();
std::string gp_id = m_gp.getId();
ModalDialog::dismiss();
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false,
(eventSource == "continue"));
@ -284,7 +284,7 @@ void GPInfoDialog::onUpdate(float dt)
m_curr_time += dt;
int frameAfter = (int)(m_curr_time / 1.5f);
const std::vector<std::string> tracks = m_gp->getTrackNames();
const std::vector<std::string> tracks = m_gp.getTrackNames();
if (frameAfter >= (int)tracks.size())
{
frameAfter = 0;

View File

@ -20,7 +20,7 @@
#define HEADER_GP_INFO_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
// Don't include grand_prix_data.hpp here or the compilation will fail
#include "race/grand_prix_data.hpp"
class GrandPrixData;
@ -39,7 +39,9 @@ class GPInfoDialog : public GUIEngine::ModalDialog
protected: // Necessary for RandomGPInfoDialog
GUIEngine::IconButtonWidget* m_screenshot_widget;
float m_curr_time;
GrandPrixData* m_gp;
/** The grand prix data. */
GrandPrixData m_gp;
/** height of the separator over the body */
int m_over_body;

View File

@ -37,7 +37,7 @@ RandomGPInfoDialog::RandomGPInfoDialog()
// Defaults - loading selection from last time frrom a file would be better
m_number_of_tracks = 2; // We can assume that there are at least 2 standard tracks
m_trackgroup = "standard";
m_use_reverse = NO_REVERSE;
m_use_reverse = GrandPrixData::NO_REVERSE;
doInit();
m_curr_time = 0.0f;
@ -46,7 +46,7 @@ RandomGPInfoDialog::RandomGPInfoDialog()
m_over_body = m_area.getHeight()/7 + SPINNER_HEIGHT + 10; // 10px space
m_lower_bound = m_area.getHeight()*6/7;
m_gp = new GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
m_gp = GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
addTitle();
addSpinners();
@ -135,14 +135,14 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent(
if (eventSource == "start")
{
ModalDialog::dismiss();
race_manager->startGP(m_gp, false, false);
race_manager->startGP(&m_gp, false, false);
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "Number of tracks")
{
// The old gp can be reused because there's only track deletion/adding
m_number_of_tracks = getWidget<Spinner>("Number of tracks")->getValue();
m_gp->changeTrackNumber(m_number_of_tracks, m_trackgroup);
m_gp.changeTrackNumber(m_number_of_tracks, m_trackgroup);
addTracks();
}
else if (eventSource == "Trackgroup")
@ -164,18 +164,18 @@ GUIEngine::EventPropagation RandomGPInfoDialog::processEvent(
if (s->getValue() > (signed)max)
s->setValue(max);
new (m_gp) GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
m_gp = GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
addTracks();
}
else if (eventSource == "reverse")
{
Spinner* r = getWidget<Spinner>("reverse");
m_use_reverse = static_cast<REVERSED>(r->getValue());
m_gp->changeReverse(m_use_reverse);
m_use_reverse = static_cast<GrandPrixData::GP_Reversed>(r->getValue());
m_gp.changeReverse(m_use_reverse);
}
else if (eventSource == "reload")
{
new (m_gp) GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
m_gp = GrandPrixData(m_number_of_tracks, m_trackgroup, m_use_reverse);
addTracks();
}

View File

@ -24,17 +24,10 @@
class RandomGPInfoDialog : public GPInfoDialog
{
public:
enum REVERSED
{
NO_REVERSE = 0,
ALL_REVERSE = 1,
MIXED = 2
};
private:
unsigned int m_number_of_tracks;
std::string m_trackgroup;
REVERSED m_use_reverse;
GrandPrixData::GP_Reversed m_use_reverse;
public:
static const int SPINNER_HEIGHT = 40;