Skip to content

Updating cache for query with up traversal fails when the matched component is removed #1775

@indianakernick

Description

@indianakernick

Describe the bug

An internal error is triggered after a component is removed from an entity that a cached query previously found via up traversal.

To Reproduce

int main() {
    struct Tag {};

    flecs::world world;

    world.component<Tag>();
    world.system().with<Tag>().up().each([](flecs::entity e) {
        std::cout << e << '\n';
    });
    world.system().run([&](flecs::iter &) {
        world.remove_all<Tag>();
    });

    flecs::entity parent = world.entity();
    parent.child();

    world.progress(); // nothing happens
    parent.add<Tag>();
    world.progress(); // system matches child entity
    world.progress(); // crashes
}

The error is this one:

fatal: cache_iter.c: 42: assert: tr != NULL INTERNAL_ERROR

Disabling caching on the system with .cache_kind(flecs::QueryCacheNone) is a workaround.

Expected behavior

This should not crash.

Additional context

Flecs version 4.1.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions