Stop music, so that its handle can be freed, before playing other music on sector...
[supertux.git] / src / supertux / sector.cpp
index 8575297..7573a95 100644 (file)
@@ -115,8 +115,15 @@ Sector::Sector(Level* parent) :
 Sector::~Sector()
 {
   using namespace scripting;
+  try
+  {
+    deactivate();
+  }
+  catch(const std::exception& err)
+  {
+    log_warning << err.what() << std::endl;
+  }
 
-  deactivate();
 
   for(auto i = scripts.begin(); i != scripts.end(); ++i) {
     HSQOBJECT& object = *i;
@@ -1490,6 +1497,20 @@ Sector::play_music(MusicType type)
   }
 }
 
+void
+Sector::resume_music()
+{
+  if(SoundManager::current()->get_current_music() == music)
+  {
+    SoundManager::current()->resume_music(1.5f);
+  }
+  else
+  {
+    SoundManager::current()->stop_music();
+    SoundManager::current()->play_music(music, true);
+  }
+}
+
 MusicType
 Sector::get_music_type()
 {