From 5e78fdc93020a09de8df07b5988908d84914f1d1 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Wed, 4 Jun 2014 06:09:59 +0200 Subject: [PATCH] Not deleting in a "foreach"-loop --- src/Systems/SoundSystem.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Systems/SoundSystem.cpp b/src/Systems/SoundSystem.cpp index 37e2947..560e6e7 100755 --- a/src/Systems/SoundSystem.cpp +++ b/src/Systems/SoundSystem.cpp @@ -59,16 +59,21 @@ void Systems::SoundSystem::Update(double dt) } //LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); - for (auto channel : m_Channels) + + std::map::iterator it; + for(it = m_Channels.begin(); it != m_Channels.end();) { FMOD_BOOL isPlaying = false; - FMOD_Channel_IsPlaying(channel.second, &isPlaying); + FMOD_Channel_IsPlaying(it->second, &isPlaying); if(!isPlaying) { - m_Channels.erase(channel.first); + it = m_Channels.erase(it); + } + else + { + it++; } } - } void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)