From 93a44a17e4fc020f34eaa8b3064711f591026650 Mon Sep 17 00:00:00 2001 From: Fat-Zer Date: Tue, 12 Aug 2025 06:41:18 +0000 Subject: [PATCH] Fix crash on collection rescan Closes: https://mirror.git.trinitydesktop.org/gitea/TDE/amarok/issues/87 Signed-off-by: Fat-Zer --- amarok/src/playlist.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/amarok/src/playlist.cpp b/amarok/src/playlist.cpp index d87c0621..d73ac8de 100644 --- a/amarok/src/playlist.cpp +++ b/amarok/src/playlist.cpp @@ -921,12 +921,15 @@ Playlist::updateEntriesStatusAdded( const TQMap &map ) TQMap*> uniquecopy( m_uniqueMap ); TQMap*>::Iterator it; - for( it = uniquecopy.begin(); it != uniquecopy.end(); ++it ) + for( it = uniquecopy.begin(); it != uniquecopy.end(); ) { - if( map.contains( it.key() )) + // remove() may invalidate the iterator, so make a copy and increment + // it before modifying the collection + TQMap*>::Iterator cur = it++; + if( map.contains( cur.key() )) { - updateEntriesStatusAdded( map[it.key()], it.key() ); - uniquecopy.remove( it ); + updateEntriesStatusAdded( map[cur.key()], cur.key() ); + uniquecopy.remove( cur ); } }