From c3af03d6fcaf08bec47d2b4812d987ee485b5f83 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 4 Mar 2010 18:38:59 +0000 Subject: [PATCH] supertux/game_session.[ch]pp: Fix a segmantation fault when loading an invalid level file. SVN-Revision: 6545 --- src/supertux/game_session.cpp | 13 ++++++++++--- src/supertux/game_session.hpp | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 88f770460..786d23ff9 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -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; @@ -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(); @@ -137,6 +139,8 @@ GameSession::restart_level() log_info << "Next run uses random seed " << g_config->random_seed <activate(currentsector->player->get_pos()); } diff --git a/src/supertux/game_session.hpp b/src/supertux/game_session.hpp index 22160a39b..17370bc16 100644 --- a/src/supertux/game_session.hpp +++ b/src/supertux/game_session.hpp @@ -79,7 +79,7 @@ public: * resources for the current level/world */ std::string get_working_directory(); - void restart_level(); + int restart_level(); void toggle_pause(); -- 2.11.0