Multiple up() terms read components from different parents
Author: HammerkegCreated Sep 11, 2026Updated Sep 11, 2026
Labelsbug
Flecs 674a96ff3d8d21d07081c4159620c07325974ee6 (4.1.6), Windows/MSVC.
When native flecs::Parent children share a table, the first up(ChildOf) field advances correctly, but the second retains the previous parent’s component.
#include "flecs.h"
#include <cstdio>
struct Child { int Value = 0; };
struct A { int Value = 0; };
struct B { int Value = 0; };
int main()
{
flecs::world world;
bool passed = true;
int count = 0;
world.system<const Child, const A, const B>()
.term_at(1).up(flecs::ChildOf)
.term_at(2).up(flecs::ChildOf)
.each([&](flecs::entity e, const Child&, const A& a, const B& b) {
++count;
std::printf("%s: A=%d, B=%d\n",
e.name().c_str(), a.Value, b.Value);
passed &= a.Value == e.parent().get<A>().Value
&& b.Value == e.parent().get<B>().Value;
});
auto p1 = world.entity().set<A>({1}).set<B>({10});
auto p2 = world.entity().set<A>({2}).set<B>({20});
world.entity(flecs::Parent{p1.id()}, "FirstChild").set<Child>({});
world.entity(flecs::Parent{p2.id()}, "SecondChild").set<Child>({});
world.progress(0.001f);
return passed && count == 2 ? 0 : 1;
}Expected second child: A=2, B=20. Actual: A=2, B=10.
Our local fix restores ctx->it->sources[op->field_index] to op_ctx->tgt when flecs_query_tree_up_post() exhausts its range, before traversal advances to the next parent.
Source: SanderMertens/flecs