Index: ps/trunk/source/simulation2/system/ComponentManager.cpp =================================================================== --- ps/trunk/source/simulation2/system/ComponentManager.cpp +++ ps/trunk/source/simulation2/system/ComponentManager.cpp @@ -909,10 +909,6 @@ std::vector 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::iterator it = queue.begin(); it != queue.end(); ++it) { entity_id_t ent = *it; @@ -921,6 +917,11 @@ 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 >::iterator iit = m_ComponentsByTypeId.begin(); for (; iit != m_ComponentsByTypeId.end(); ++iit)