Skip to content

Commit

Permalink
supertux/game_session.[ch]pp: Fix a segmantation fault when loading a…
Browse files Browse the repository at this point in the history
…n invalid level file.

SVN-Revision: 6545
  • Loading branch information
Florian Forster committed Mar 4, 2010
1 parent 9324a91 commit c3af03d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/supertux/game_session.cpp
Expand Up @@ -76,18 +76,19 @@ GameSession::GameSession(const std::string& levelfile_, PlayerStatus* player_sta

statistics_backdrop = Surface::create("images/engine/menu/score-backdrop.png");

restart_level();
if (restart_level() != 0)
throw std::runtime_error ("Initializing the level failed.");

game_menu.reset(new GameMenu(*level));
}

void
int
GameSession::restart_level()
{

if (edit_mode) {
force_ghost_mode();
return;
return (-1);
}

game_pause = false;
Expand Down Expand Up @@ -124,6 +125,7 @@ GameSession::restart_level()
} catch(std::exception& e) {
log_fatal << "Couldn't start level: " << e.what() << std::endl;
g_screen_manager->exit_screen();
return (-1);
}

sound_manager->stop_music();
Expand All @@ -137,6 +139,8 @@ GameSession::restart_level()
log_info << "Next run uses random seed " << g_config->random_seed <<std::endl;
record_demo(capture_file);
}

return (0);
}

GameSession::~GameSession()
Expand Down Expand Up @@ -403,6 +407,9 @@ GameSession::process_menu()
void
GameSession::setup()
{
if (currentsector == NULL)
return;

if(currentsector != Sector::current()) {
currentsector->activate(currentsector->player->get_pos());
}
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/game_session.hpp
Expand Up @@ -79,7 +79,7 @@ class GameSession : public Screen,
* resources for the current level/world
*/
std::string get_working_directory();
void restart_level();
int restart_level();

void toggle_pause();

Expand Down

0 comments on commit c3af03d

Please sign in to comment.