From c916185a7c6653d21ab00fce5295b72b6aab708b Mon Sep 17 00:00:00 2001 From: stiffly Date: Thu, 14 Jan 2016 15:06:26 +0100 Subject: [PATCH] Does not crash when removing soundemitter component. --- src/Engine/Sound/SoundSystem.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index d21d1cd8..3c37d2b2 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -59,16 +59,16 @@ void SoundSystem::deleteInactiveEmitters() { std::unordered_map::iterator it; for (it = m_Sources.begin(); it != m_Sources.end();) { - if (m_World->ValidEntity((*it).first)) { + if (m_World->ValidEntity(it->first) + && m_World->HasComponent(it->first, "SoundEmitter")) { if (getSourceState(it->second->ALsource) != AL_STOPPED) { // Nothing to see here, move along it++; continue; } else { - // Sound has been stopped / finished playing + // Sound has been stopped / finished playing. And has correct component. alDeleteBuffers(1, &it->second->ALsource); alDeleteSources(1, &it->second->ALsource); - delete it->second->SoundResource; m_World->DeleteEntity(it->first); it = m_Sources.erase(it); } @@ -77,7 +77,6 @@ void SoundSystem::deleteInactiveEmitters() stopSound((*it).second); alDeleteBuffers(1, &it->second->ALsource); alDeleteSources(1, &it->second->ALsource); - delete it->second->SoundResource; it = m_Sources.erase(it); } }