]> git.tdb.fi Git - r2c2.git/commitdiff
Don't fail when adding multiple tracks to an initially empty Route
authorMikko Rasa <tdb@tdb.fi>
Wed, 29 May 2013 20:33:52 +0000 (23:33 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 29 May 2013 20:33:52 +0000 (23:33 +0300)
source/libr2c2/route.cpp

index 788b235658ff53b148ee36c18b47ef65c268eeec..38ea9f681d77da64f10600b369124c27724aca59 100644 (file)
@@ -272,14 +272,21 @@ void Route::add_tracks(const set<Track *> &trks)
                if(!tracks.count(*i))
                        pending.insert(*i);
 
+       if(tracks.empty())
+       {
+               set<Track *>::iterator i = pending.begin();
+               tracks.insert(*i);
+               pending.erase(i);
+       }
+
        while(!pending.empty())
        {
                RouteValidityMask valid = ROUTE_INVALID;
-               for(set<Track *>::const_iterator i=pending.begin(); i!=pending.end(); ++i)
-                       if(tracks.empty() || (valid=check_validity(**i))==ROUTE_VALID)
+               for(set<Track *>::iterator i=pending.begin(); i!=pending.end(); ++i)
+                       if((valid=check_validity(**i))==ROUTE_VALID)
                        {
                                tracks.insert(*i);
-                               pending.erase(*i);
+                               pending.erase(i);
                                break;
                        }