Sdk/Entity: Fix OnDetached being called after OnEntityRemove when destructing

This commit is contained in:
Jérôme Leclercq 2017-03-08 16:32:08 +01:00
parent 9c7b2ed4b8
commit 0818a2187b
1 changed files with 5 additions and 4 deletions

View File

@ -152,6 +152,10 @@ namespace Ndk
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
m_components[i]->OnEntityDestruction();
// Detach components while they're still attached to systems
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
m_components[i]->SetEntity(nullptr);
// We alert each system
for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
{
@ -165,10 +169,7 @@ namespace Ndk
}
m_systemBits.Clear();
// We properly destroy each component
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
m_components[i]->SetEntity(nullptr);
// Destroy components
m_components.clear();
m_componentBits.Reset();