# HG changeset patch # User Chris Cannam # Date 1441639435 -3600 # Node ID 0af00da90a40b06997965d855d372555f638b573 # Parent 7dcff010d9cde72d1b30b8c64f7d0a6b83479d82 Copy the column before potentially erasing while iterating through it diff -r 7dcff010d9cd -r 0af00da90a40 src/Silvet.cpp --- a/src/Silvet.cpp Mon Sep 07 14:45:19 2015 +0100 +++ b/src/Silvet.cpp Mon Sep 07 16:23:55 2015 +0100 @@ -1059,11 +1059,14 @@ if (width < durationThreshold + 1) { return { noteFeatures, onsetFeatures, onOffsetFeatures }; } + + // Make a copy of the latest column. We need a copy because it is + // possible we may erase from the "live" column within the loop. + map latest = m_pianoRoll[width-1]; - for (map::const_iterator ni = m_pianoRoll[width-1].begin(); - ni != m_pianoRoll[width-1].end(); ++ni) { + for (const auto &ni: latest) { - int note = ni->first; + int note = ni.first; int end = width; int start = end-1; @@ -1100,7 +1103,9 @@ m_current.erase(note); emitNoteAndOffset(start, end-1, note, noteFeatures, onOffsetFeatures); // and remove this so that we start counting the new - // note's duration from the current position + // note's duration from the current position. (This + // erase is why we needed to copy this column at the + // top of the loop.) m_pianoRoll[width-1].erase(note); } }