From 26b2351d4b04122d51c140b2d35325c02ccb0a5a Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 6 May 2024 13:48:02 -0700 Subject: [PATCH] module: fix zero-size component bug Signed-off-by: Stephen Gutekanst --- src/module/Archetype.zig | 1 - src/module/entities.zig | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/module/Archetype.zig b/src/module/Archetype.zig index 35d2476e..a86cc67a 100644 --- a/src/module/Archetype.zig +++ b/src/module/Archetype.zig @@ -172,7 +172,6 @@ pub fn setDynamic(storage: *Archetype, row_index: u32, name: StringTable.Index, } pub fn get(storage: *Archetype, row_index: u32, name: StringTable.Index, comptime ColumnType: type) ?ColumnType { - if (@sizeOf(ColumnType) == 0) return {}; if (is_debug) debugAssertColumnType(storage, storage.columnByName(name) orelse return null, ColumnType); const bytes = storage.getDynamic(row_index, name, @sizeOf(ColumnType), @alignOf(ColumnType), typeId(ColumnType)) orelse return null; diff --git a/src/module/entities.zig b/src/module/entities.zig index 228ef277..7a38a8a5 100644 --- a/src/module/entities.zig +++ b/src/module/entities.zig @@ -885,11 +885,11 @@ test "example" { try world.setComponent(player1, .game, .is_monster, {}); try testing.expectEqual(@as(?void, {}), world.getComponent(player1, .game, .is_monster)); - try testing.expectEqual(@as(?void, {}), world.getComponent(player2, .game, .is_monster)); // BUG: this reports non-null when it should report null! + try testing.expectEqual(@as(?void, null), world.getComponent(player2, .game, .is_monster)); try world.removeComponent(player1, .game, .is_monster); - try testing.expectEqual(@as(?void, {}), world.getComponent(player1, .game, .is_monster)); // BUG: this reports non-null when it should report null! - try testing.expectEqual(@as(?void, {}), world.getComponent(player2, .game, .is_monster)); // BUG: this reports non-null when it should report null! + try testing.expectEqual(@as(?void, null), world.getComponent(player1, .game, .is_monster)); + try testing.expectEqual(@as(?void, null), world.getComponent(player2, .game, .is_monster)); //------------------------------------------------------------------------- // Introspect things.