zig-ecs icon indicating copy to clipboard operation
zig-ecs copied to clipboard

Using two groups at the same time

Open jptrzy opened this issue 2 years ago • 2 comments

I don't get it, why doesn't it work 🤔

Code:

...
{
    var group = world.group(.{ Position, Orbiting }, .{}, .{});
    var group_iter = group.iterator(struct { pos: *Position, orb: *Orbiting });

    while (group_iter.next()) |e| {
        ...
    }
}

{
    var group = world.group(.{ Position, Renderer }, .{}, .{});
    var group_iter = group.iterator(struct { pos: *Position, ren: *Renderer });

    while (group_iter.next()) |e| {
        ...
    }
}
...

Error Logs:

thread 258336 panic: reached unreachable code
/nix/store/ypzkr8d6sff2vcdjadcbblqdwjf1ia72-zig-0.12.0-dev.1+a327d8b99/lib/std/debug.zig:343:14: 0x342e6c in assert (z-space)
    if (!ok) unreachable; // assertion failure
             ^
/home/jp3/.local/src/z-space/libs/zig-ecs/src/ecs/registry.zig:530:33: 0x344d73 in group__anon_6485 (z-space)
                std.debug.assert(check);
                                ^
/home/jp3/.local/src/z-space/src/main.zig:74:36: 0x3424b4 in main (z-space)
            var group = world.group(.{ Position, Renderer }, .{}, .{});
                                   ^
/nix/store/ypzkr8d6sff2vcdjadcbblqdwjf1ia72-zig-0.12.0-dev.1+a327d8b99/lib/std/start.zig:564:22: 0x341dc9 in main (z-space)
            root.main();
                     ^
???:?:?: 0x7ffff7d1facd in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7ffff7d1facd` was not available, trace may be incomplete

PS. Did you thought about adding better error messages - it would have been really helpful 😄

jptrzy avatar Aug 05 '23 22:08 jptrzy

Did you ever figure out why this was happening? I just ran into the same issue.

cowboy8625 avatar Aug 25 '24 20:08 cowboy8625

@cowboy8625 a quick read into the source code revealed that the first parameter passed to group can not share any one of the components to other calls to group. That parameter is called owned and reading up a bit from the original entt lib, it seems that that's how it works there as well.

The solution given was to try not to have groups but views until you reach a bottleneck.

Link to the entt discussion.

However, it would be nice with more compiler errors that explain what the issue is.

lumorsunil avatar Oct 27 '24 18:10 lumorsunil