1
0
forked from 0ad/0ad

Add a test to the component manager to show a crash in dynamic subscriptions when components unsubscribe during deletion. Reviewed by wraitii.

Differential Revision: https://code.wildfiregames.com/D346
This was SVN commit r19423.
This commit is contained in:
fatherbushido 2017-04-17 07:55:44 +00:00
parent adf60c7c49
commit de9e76cbf1
2 changed files with 26 additions and 0 deletions

View File

@ -32,6 +32,7 @@ public:
{
componentManager.SubscribeToMessageType(MT_TurnStart);
componentManager.SubscribeToMessageType(MT_Interpolate);
componentManager.SubscribeToMessageType(MT_Destroy);
}
DEFAULT_COMPONENT_ALLOCATOR(Test1A)
@ -74,6 +75,9 @@ public:
{
switch (msg.GetType())
{
case MT_Destroy:
GetSimContext().GetComponentManager().DynamicSubscriptionNonsync(MT_RenderSubmit, this, false);
break;
case MT_TurnStart:
m_x += 1;
break;

View File

@ -854,4 +854,26 @@ entities:\n\
TS_ASSERT(man2.DeserializeState(stateStream));
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 12347);
}
void test_dynamic_subscription()
{
CSimContext context;
CComponentManager man(context, g_ScriptRuntime);
man.LoadComponentTypes();
entity_id_t ent1 = 1;
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
CParamNode noParam;
man.AddComponent(hnd1, CID_Test1A, noParam);
man.AddComponent(hnd1, CID_Test2A, noParam);
man.DynamicSubscriptionNonsync(MT_RenderSubmit, man.QueryInterface(ent1, IID_Test1), true);
man.DynamicSubscriptionNonsync(MT_RenderSubmit, man.QueryInterface(ent1, IID_Test2), true);
man.DestroyComponentsSoon(ent1);
man.FlushDestroyedComponents();
}
};