Fix undefined behavior when creating the item slot string.

Fixes #260
This commit is contained in:
IntegratedQuantum 2024-01-26 10:10:32 +01:00
parent 178489b044
commit d215755415
2 changed files with 2 additions and 2 deletions

View File

@ -85,7 +85,7 @@ pub fn init(pos: Vec2f, itemStack: ItemStack, vtable: *const VTable, userData: u
.vtable = vtable,
.userData = userData,
.pos = pos,
.text = try TextBuffer.init(main.globalAllocator, std.fmt.bufPrint(&buf, "{}", .{self.itemStack.amount}) catch "", .{}, false, .right),
.text = try TextBuffer.init(main.globalAllocator, std.fmt.bufPrint(&buf, "{}", .{itemStack.amount}) catch "", .{}, false, .right),
.texture = texture.value(),
.mode = mode,
};

View File

@ -46,7 +46,7 @@ pub fn onOpen() Allocator.Error!void {
for(0..8) |_| {
if(i >= items.items.len) break;
const item = items.items[i];
try row.add(try ItemSlot.init(.{0, 0}, .{.item = item, .amount = item.stackSize()}, &.{.tryTakingItems = &tryTakingItems}, i, .default, .takeOnly));
try row.add(try ItemSlot.init(.{0, 0}, .{.item = item, .amount = 1}, &.{.tryTakingItems = &tryTakingItems}, i, .default, .takeOnly));
i += 1;
}
try list.add(row);