supertux/game_session.[ch]pp: Fix a segmantation fault when loading an invalid level...
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 4 Mar 2010 18:38:59 +0000 (18:38 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Thu, 4 Mar 2010 18:38:59 +0000 (18:38 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6545 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/supertux/game_session.cpp
src/supertux/game_session.hpp

index 88f7704..786d23f 100644 (file)
@@ -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 <<std::endl;
     record_demo(capture_file);
   }
+
+  return (0);
 }
 
 GameSession::~GameSession()
@@ -403,6 +407,9 @@ GameSession::process_menu()
 void
 GameSession::setup()
 {
+  if (currentsector == NULL)
+    return;
+
   if(currentsector != Sector::current()) {
     currentsector->activate(currentsector->player->get_pos());
   }
index 22160a3..17370bc 100644 (file)
@@ -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();