From 58ddba4178e9580c8ade45571a21e405e95c4e81 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 28 May 2017 20:56:15 +0200 Subject: [PATCH] Ensure the track ID is unique --- genericcontainer.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/genericcontainer.h b/genericcontainer.h index 73ca8dd..86ca245 100644 --- a/genericcontainer.h +++ b/genericcontainer.h @@ -294,7 +294,9 @@ inline void GenericContainer::rem * \sa areTracksParsed() * \sa parseTracks() * - * \remarks The container takes ownership over the specified \a track if it was possible to add the track. + * \remarks The container takes ownership over the specified \a track if it was possible + * to add the track. This makes adding a track from another container impossible + * without removing it from the other container first. * * \returns Returns an indication whether the \a track could be added. */ @@ -302,6 +304,17 @@ template bool GenericContainer::addTrack(TrackType *track) { if(areTracksParsed() && supportsTrackModifications()) { + // ensure ID is unique + auto id = track->id(); + ensureIdIsUnique: + for(const auto &track : m_tracks) { + if(track->id() == id) { + ++id; + goto ensureIdIsUnique; + } + } + track->setId(id); + m_tracks.emplace_back(track); return m_tracksAltered = true; }