mail[Wesnoth-commits] r34257 - /branches/1.6/src/sound.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by shadowm2006 on March 29, 2009 - 22:32:
Author: shadowmaster
Date: Sun Mar 29 22:32:55 2009
New Revision: 34257

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34257&view=rev
Log:
Avoid an infinite loop when no music playlist entries are valid (e.g.
when none of them could be resolved to file paths).

This was an obvious blocker for people who don't install the
wesnoth-music package in Debian. ;(

Modified:
    branches/1.6/src/sound.cpp

Modified: branches/1.6/src/sound.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.6/src/sound.cpp?rev=34257&r1=34256&r2=34257&view=diff
==============================================================================
--- branches/1.6/src/sound.cpp (original)
+++ branches/1.6/src/sound.cpp Sun Mar 29 22:32:55 2009
@@ -138,6 +138,8 @@
 typedef std::list< sound_cache_chunk >::iterator sound_cache_iterator;
 std::map<std::string,Mix_Music*> music_cache;
 
+struct no_valid_tracks {};
+
 struct music_track
 {
        music_track(const std::string &tname);
@@ -186,6 +188,9 @@
 
 static bool track_ok(const std::string &name)
 {
+       if(name.empty()) {
+               return false;
+       }
        LOG_AUDIO << "Considering " << name << "\n";
 
        // If they committed changes to list, we forget previous plays, but
@@ -245,6 +250,17 @@
 static const music_track &choose_track()
 {
        assert(!current_track_list.empty());
+
+       bool all_invalid = true;
+       foreach(const music_track& mt, current_track_list) {
+               if(!mt.name.empty()) {
+                       all_invalid = false;
+                       break;
+               }
+       }
+       if(all_invalid) {
+               throw no_valid_tracks();
+       }
 
        std::string name;
        unsigned int track = 0;
@@ -607,23 +623,28 @@
 
 void music_thinker::process(events::pump_info &info) {
        if(preferences::music_on()) {
-               if(!music_start_time && !current_track_list.empty() && 
!Mix_PlayingMusic()) {
-                       // Pick next track, add ending time to its start time.
-                       current_track = choose_track();
-                       music_start_time = info.ticks();
-                       no_fading=true;
-                       fadingout_time=0;
-               }
-
-               if(music_start_time && info.ticks(&music_refresh, 
music_refresh_rate) >= music_start_time - fadingout_time) {
-                       want_new_music=true;
-               }
-
-               if(want_new_music) {
-                       if(Mix_PlayingMusic()) {
-                               Mix_FadeOutMusic(fadingout_time);
-                       }
-                       play_new_music();
+               try {
+                       if(!music_start_time && !current_track_list.empty() 
&& !Mix_PlayingMusic()) {
+                               // Pick next track, add ending time to its 
start time.
+                               current_track = choose_track();
+                               music_start_time = info.ticks();
+                               no_fading=true;
+                               fadingout_time=0;
+                       }
+
+                       if(music_start_time && info.ticks(&music_refresh, 
music_refresh_rate) >= music_start_time - fadingout_time) {
+                               want_new_music=true;
+                       }
+
+                       if(want_new_music) {
+                               if(Mix_PlayingMusic()) {
+                                       Mix_FadeOutMusic(fadingout_time);
+                               }
+                               play_new_music();
+                       }
+               }
+               catch(no_valid_tracks const&) {
+                       current_track_list.clear();
                }
        }
 }




Related Messages


Powered by MHonArc, Updated Sun Mar 29 23:00:30 2009