Skip to content

Transitions from rootArchetype to rootArchetype fail 0.9.0-beta.0 #157

@TheyCallMeRyan

Description

@TheyCallMeRyan

Description

Image
With the way transitionArchetypes works, transitioning from the same archetype to itself will always set the entityRecord.indexInArchetype to the number of elements in archetype.entities + 1, but it will also then put it back in the position it previously held. This leads to the indexInArchetype being 1 higher than the number of elements in archetype.entities every time. If additional entities are then added to it, multiple entities will have the same reference to the same element in the list. This makes it possible to remove an entity from archetype.entities that exists without removing the element that no longer exists.

Steps to reproduce

world:startDeferring()
world:commitCommands()
world:spawnAt(1)
world:spawnAt(2)
world:spawnAt(3)
world:spawnAt(4)
world:spawnAt(5)
world:commitCommands()
world:replace(3)
world:replace(4)
world:commitCommands()
world:spawnAt(6)
world:commitCommands()
world:despawn(4)
world:despawn(3)
world:commitCommands()
world:insert(2, Component({text = "Test 1"}))
world:commitCommands()

^ Guaranteed to get the above error

Expected behavior

The example above is a bit contrived, but I think the more common case would be if you had an entity that had no components and then you despawn it. Both executeDespawn and executeReplace have this issue because they start by transitioning to the rootArchetype before anything else.

I would expect to see this happen if, for example, the server is replicating entities to the client, and the client then removes all components from one such entity without despawning it, and eventually the server tells it to despawn the entity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions