--- libgig/trunk/src/gig.cpp 2021/07/19 14:35:37 3978 +++ libgig/trunk/src/gig.cpp 2021/07/19 14:43:22 3979 @@ -6659,7 +6659,9 @@ // this string is needed for the gig to be loadable in GSt: pInstrument->pInfo->Software = "Endless Wave"; + const size_t idxIt = InstrumentsIterator - pInstruments->begin(); pInstruments->push_back(pInstrument); + InstrumentsIterator = pInstruments->begin() + std::min(idxIt, pInstruments->size()); // avoid iterator invalidation return pInstrument; } @@ -6771,7 +6773,9 @@ if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments"); InstrumentList::iterator iter = find(pInstruments->begin(), pInstruments->end(), (DLS::Instrument*) pInstrument); if (iter == pInstruments->end()) throw gig::Exception("Could not delete instrument, could not find given instrument"); + const size_t idxIt = InstrumentsIterator - pInstruments->begin(); pInstruments->erase(iter); + InstrumentsIterator = pInstruments->begin() + std::min(idxIt, pInstruments->size()); // avoid iterator invalidation pInstrument->DeleteChunks(); delete pInstrument; }