From b26ad4c44629731a40e4251a3374af508d27a141 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 31 May 2016 11:07:46 -1000 Subject: [PATCH] Object lifetime fixes --- lib/Engine.cpp | 24 ++++-------------------- lib/Sequencer.cpp | 5 +++-- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/Engine.cpp b/lib/Engine.cpp index 8849e96..6db19d3 100644 --- a/lib/Engine.cpp +++ b/lib/Engine.cpp @@ -76,7 +76,6 @@ Engine::_allocateSequencer(const AudioGroup& group, int groupId, return {}; auto it = m_activeSequencers.emplace(m_activeSequencers.end(), new Sequencer(*this, group, groupId, *songGroup, setupId, smx)); - printf("INSERT %p\n", it->get()); return it; } @@ -105,9 +104,7 @@ std::list>::iterator Engine::_destroySequencer(std::l #endif if ((*it)->m_destroyed) return m_activeSequencers.begin(); - printf("TO DESTROY %p\n", it->get()); (*it)->_destroy(); - printf("ERASE %p\n", it->get()); return m_activeSequencers.erase(it); } @@ -288,34 +285,21 @@ Submix* Engine::addSubmix(Submix* smx) std::list::iterator Engine::_removeSubmix(std::list::iterator smx) { /* Delete all voices bound to submix */ - for (auto it = m_activeVoices.begin() ; it != m_activeVoices.end() ;) + for (auto it = m_activeVoices.begin() ; it != m_activeVoices.end() ; ++it) { Voice* vox = it->get(); - Submix* vsmx = vox->getSubmix(); if (vsmx == &*smx) - { - vox->_destroy(); - it = m_activeVoices.erase(it); - continue; - } - ++it; + vox->kill(); } /* Delete all sequencers bound to submix */ - for (auto it = m_activeSequencers.begin() ; it != m_activeSequencers.end() ;) + for (auto it = m_activeSequencers.begin() ; it != m_activeSequencers.end() ; ++it) { Sequencer* seq = it->get(); - Submix* ssmx = seq->getSubmix(); if (ssmx == &*smx) - { - if (!seq->m_destroyed) - seq->_destroy(); - it = m_activeSequencers.erase(it); - continue; - } - ++it; + seq->kill(); } /* Delete all submixes bound to submix */ diff --git a/lib/Sequencer.cpp b/lib/Sequencer.cpp index d28bb7e..56008d3 100644 --- a/lib/Sequencer.cpp +++ b/lib/Sequencer.cpp @@ -45,7 +45,6 @@ void Sequencer::_bringOutYourDead() void Sequencer::_destroy() { - printf("DESTROY %p\n", this); Entity::_destroy(); if (m_submix) { @@ -56,9 +55,11 @@ void Sequencer::_destroy() Sequencer::~Sequencer() { - printf("DEALLOC %p\n", this); if (m_submix) + { m_engine.removeSubmix(m_submix); + m_submix = nullptr; + } } Sequencer::Sequencer(Engine& engine, const AudioGroup& group, int groupId,