From d215755415be60a22513197ce9e25da408d85080 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Fri, 26 Jan 2024 10:10:32 +0100 Subject: [PATCH] Fix undefined behavior when creating the item slot string. Fixes #260 --- src/gui/components/ItemSlot.zig | 2 +- src/gui/windows/creative_inventory.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/components/ItemSlot.zig b/src/gui/components/ItemSlot.zig index 66f0af8c..7bc67361 100644 --- a/src/gui/components/ItemSlot.zig +++ b/src/gui/components/ItemSlot.zig @@ -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, }; diff --git a/src/gui/windows/creative_inventory.zig b/src/gui/windows/creative_inventory.zig index 0b0e92d7..6b7862e1 100644 --- a/src/gui/windows/creative_inventory.zig +++ b/src/gui/windows/creative_inventory.zig @@ -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);