SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
MIT License
5.82k stars 412 forks source link

World destruction with symmetric relationship and child causes assertion #1212

Open awest03 opened 2 weeks ago

awest03 commented 2 weeks ago

Describe the bug When a world's destructor is called (C++ api), an assertion (fatal: entity.c: 3893: assert: entity != 0 INVALID_PARAMETER) fails if there is an entity which is a child of another entity and has a symmetric relationship with another entity, that is or is not a child of the same entity.

To Reproduce This code will trigger the bug:

#include <flecs.h>

struct Buddies {};

int main()
{
    flecs::world ecs;

    ecs.component<Buddies>().add(flecs::Symmetric);

    flecs::entity idk = ecs.entity("Idk");
    flecs::entity bob = ecs.entity("Bob")
        .child_of(idk);
    ecs.entity("Alice")
        .child_of(idk)
        .add<Buddies>(bob);

    return 0;
}

Expected behavior No assertion

Additional context

SanderMertens commented 1 week ago

Fixed on the v4 branch

awest03 commented 5 days ago

Thanks, it looks like the bug may still be there as the code I posted above still doesn't work on the latest v4 branch, if I add:

ecs.remove_all<Buddies>(flecs::Wildcard);

before exiting there isn't a problem, so definitely still related to the symmetric relationship