Skip to content

Commit

Permalink
Fix: Loading a level in editor after playing a level causes crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Hume2 committed Mar 7, 2016
1 parent 0bd3196 commit 17c84d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Editor::Editor() :
save_request(false),
test_request(false),
currentsector(),
m_savegame(),
levelloaded(false),
leveltested(false),
tileset(NULL),
Expand Down Expand Up @@ -303,6 +304,8 @@ Editor::setup() {
MenuManager::instance().push_menu(MenuStorage::EDITOR_LEVELSET_SELECT_MENU);
tileselect.setup();
layerselect.setup();
m_savegame.reset(new Savegame("levels/misc"));
m_savegame->load();
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "util/currenton.hpp"

class Level;
class Savegame;
class Sector;
class TileSet;
class World;
Expand Down Expand Up @@ -68,6 +69,7 @@ class Editor : public Screen,
}

Sector* currentsector;
std::unique_ptr<Savegame> m_savegame;

bool levelloaded;
bool leveltested;
Expand Down
3 changes: 3 additions & 0 deletions src/object/firefly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Firefly::Firefly(const ReaderMapping& lisp) :
void
Firefly::reactivate()
{
if (!GameSession::current()) {
return;
}
if(!GameSession::current()->get_reset_point_sectorname().empty() &&
GameSession::current()->get_reset_point_pos() == initial_position) {
// TODO: && GameSession::current()->get_reset_point_sectorname() == <sector this firefly is in>
Expand Down
11 changes: 10 additions & 1 deletion src/supertux/sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ Sector::Sector(Level* parent) :
camera(0),
effect(0)
{
add_object(std::make_shared<Player>(GameSession::current()->get_savegame().get_player_status(), "Tux"));
PlayerStatus* player_status;
if (EditorActive()) {
player_status = Editor::current()->m_savegame->get_player_status();
} else {
player_status = GameSession::current()->get_savegame().get_player_status();
}
if (!player_status) {
log_warning << "Player status is not initialized." << std::endl;
}
add_object(std::make_shared<Player>(player_status, "Tux"));
add_object(std::make_shared<DisplayEffect>("Effect"));
add_object(std::make_shared<TextObject>("Text"));

Expand Down

0 comments on commit 17c84d7

Please sign in to comment.