1
1
forked from 0ad/0ad

Fix crash in dynamic subscriptions when components unsubscribe during deletion.

Discussed with Philip.
Reviewed by fatherbushido
Differential Revision: https://code.wildfiregames.com/D264
This was SVN commit r19424.
This commit is contained in:
wraitii 2017-04-17 08:00:41 +00:00
parent de9e76cbf1
commit 1ec41f6dd0

View File

@ -909,10 +909,6 @@ void CComponentManager::FlushDestroyedComponents()
std::vector<entity_id_t> queue;
queue.swap(m_DestructionQueue);
// Flatten all the dynamic subscriptions to ensure there are no dangling
// references in the 'removed' lists to components we're going to delete
FlattenDynamicSubscriptions();
for (std::vector<entity_id_t>::iterator it = queue.begin(); it != queue.end(); ++it)
{
entity_id_t ent = *it;
@ -921,6 +917,11 @@ void CComponentManager::FlushDestroyedComponents()
CMessageDestroy msg(ent);
PostMessage(ent, msg);
// Flatten all the dynamic subscriptions to ensure there are no dangling
// references in the 'removed' lists to components we're going to delete
// Some components may have dynamically unsubscribed following the Destroy message
FlattenDynamicSubscriptions();
// Destroy the components, and remove from m_ComponentsByTypeId:
std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::iterator iit = m_ComponentsByTypeId.begin();
for (; iit != m_ComponentsByTypeId.end(); ++iit)