Object lifetime fixes

This commit is contained in:
Jack Andersen 2016-05-31 11:07:46 -10:00
parent 16c105fadb
commit b26ad4c446
2 changed files with 7 additions and 22 deletions

View File

@ -76,7 +76,6 @@ Engine::_allocateSequencer(const AudioGroup& group, int groupId,
return {}; return {};
auto it = m_activeSequencers.emplace(m_activeSequencers.end(), auto it = m_activeSequencers.emplace(m_activeSequencers.end(),
new Sequencer(*this, group, groupId, *songGroup, setupId, smx)); new Sequencer(*this, group, groupId, *songGroup, setupId, smx));
printf("INSERT %p\n", it->get());
return it; return it;
} }
@ -105,9 +104,7 @@ std::list<std::shared_ptr<Sequencer>>::iterator Engine::_destroySequencer(std::l
#endif #endif
if ((*it)->m_destroyed) if ((*it)->m_destroyed)
return m_activeSequencers.begin(); return m_activeSequencers.begin();
printf("TO DESTROY %p\n", it->get());
(*it)->_destroy(); (*it)->_destroy();
printf("ERASE %p\n", it->get());
return m_activeSequencers.erase(it); return m_activeSequencers.erase(it);
} }
@ -288,34 +285,21 @@ Submix* Engine::addSubmix(Submix* smx)
std::list<Submix>::iterator Engine::_removeSubmix(std::list<Submix>::iterator smx) std::list<Submix>::iterator Engine::_removeSubmix(std::list<Submix>::iterator smx)
{ {
/* Delete all voices bound to submix */ /* 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(); Voice* vox = it->get();
Submix* vsmx = vox->getSubmix(); Submix* vsmx = vox->getSubmix();
if (vsmx == &*smx) if (vsmx == &*smx)
{ vox->kill();
vox->_destroy();
it = m_activeVoices.erase(it);
continue;
}
++it;
} }
/* Delete all sequencers bound to submix */ /* 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(); Sequencer* seq = it->get();
Submix* ssmx = seq->getSubmix(); Submix* ssmx = seq->getSubmix();
if (ssmx == &*smx) if (ssmx == &*smx)
{ seq->kill();
if (!seq->m_destroyed)
seq->_destroy();
it = m_activeSequencers.erase(it);
continue;
}
++it;
} }
/* Delete all submixes bound to submix */ /* Delete all submixes bound to submix */

View File

@ -45,7 +45,6 @@ void Sequencer::_bringOutYourDead()
void Sequencer::_destroy() void Sequencer::_destroy()
{ {
printf("DESTROY %p\n", this);
Entity::_destroy(); Entity::_destroy();
if (m_submix) if (m_submix)
{ {
@ -56,9 +55,11 @@ void Sequencer::_destroy()
Sequencer::~Sequencer() Sequencer::~Sequencer()
{ {
printf("DEALLOC %p\n", this);
if (m_submix) if (m_submix)
{
m_engine.removeSubmix(m_submix); m_engine.removeSubmix(m_submix);
m_submix = nullptr;
}
} }
Sequencer::Sequencer(Engine& engine, const AudioGroup& group, int groupId, Sequencer::Sequencer(Engine& engine, const AudioGroup& group, int groupId,