sebas77/Svelto.ECS

[3.5.0-pre] Key not found exception when removing the same entity multiple times

Closed this issue · 1 comments

The following error is thrown when removing the same entity twice

    void Test()
    {
        var simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();
        var enginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler);

        var entityFactory = enginesRoot.GenerateEntityFactory();
        var entityFunctions = enginesRoot.GenerateEntityFunctions();

        var r = entityFactory.BuildEntity<EntityDescriptor>(2, BuildGroup);
        simpleSubmissionEntityViewScheduler.SubmitEntities();
        entityFunctions.RemoveEntity<EntityDescriptor>(r.EGID);
        entityFunctions.RemoveEntity<EntityDescriptor>(r.EGID);
        simpleSubmissionEntityViewScheduler.SubmitEntities();
    }


    record struct ComponentA(uint A1) : IEntityComponent;

    sealed class EntityDescriptor : GenericEntityDescriptor<ComponentA> { }
Svelto.DataStructures.SveltoDictionaryException: Key not found
   at Svelto.ECS.EnginesRoot.RemoveEntities(FasterDictionary`2 removeOperations, FasterList`1 entitiesRemoved, EnginesRoot enginesRoot)
   at Svelto.ECS.EntitiesOperations.ExecuteRemoveAndSwappingOperations(Action`3 swapEntities, Action`3 removeEntities, Action`2 removeGroup, Action`3 swapGroup, EnginesRoot enginesRoot)
   at Svelto.ECS.EnginesRoot.EntitiesSubmitter.SubmitEntities()
   at Svelto.ECS.Schedulers.SimpleEntitiesSubmissionScheduler.SubmitEntities()
   at AmmoTest.ECS.MultipleRemoveTests.ShouldNotThrowForMultipleRemove() in E:\projects\akrogames\ammo\ammo-server\tests\AmmoTest\ECS\MultipleRemoveTests.cs:line 51
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

I also debugged it and the issue is probably that

enginesRoot._entityLocator.RemoveEntityReference(entitiesRemoved[i]);

calls into an entitylocator remove

var reference = FetchAndRemoveReference(@egid);

and it fails here:

EntityReference reference = egidToReference[@from.entityID]; //todo: double searching fro entityID

the egidToReference does not contain the egid that we're removing the second time

ok fixed thanks