From 9006180b73b050d956b38cc1e4eec3d4ac9f1819 Mon Sep 17 00:00:00 2001 From: florianf 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. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6545 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- 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