SanderMertens / flecs

A fast entity component system (ECS) for C & C++
https://www.flecs.dev
Other
6.46k stars 454 forks source link

World destruction with symmetric relationship and child causes assertion #1212

Closed awest03 closed 4 months ago

awest03 commented 5 months 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 4 months ago

Fixed on the v4 branch

awest03 commented 4 months 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

SanderMertens commented 4 months ago

Second attempt, should be fixed now :)

awest03 commented 4 months ago

Thank you! Seems to be working for me now