prime31 / zig-ecs

MIT License
251 stars 39 forks source link

Using two groups at the same time #35

Open jptrzy opened 1 year ago

jptrzy commented 1 year ago

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 😄

cowboy8625 commented 2 months ago

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

lumorsunil commented 1 week ago

@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.