module: fix zero-size component bug

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-05-06 13:48:02 -07:00
parent 1b65702ae8
commit 26b2351d4b
2 changed files with 3 additions and 4 deletions

View file

@ -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 { 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); 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; const bytes = storage.getDynamic(row_index, name, @sizeOf(ColumnType), @alignOf(ColumnType), typeId(ColumnType)) orelse return null;

View file

@ -885,11 +885,11 @@ test "example" {
try world.setComponent(player1, .game, .is_monster, {}); 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(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 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, null), 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));
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Introspect things. // Introspect things.