Fix problem when closing, then reopening a shared inventory.

This happened because it was reusing the "freed" inventory because it still had the same Source value.

fixes #782
This commit is contained in:
IntegratedQuantum 2024-11-17 01:08:05 +01:00
parent 5044fa89d0
commit ee63168add

View File

@ -141,6 +141,7 @@ pub const Sync = struct { // MARK: Sync
self.users.deinit(main.globalAllocator); self.users.deinit(main.globalAllocator);
self.inv._deinit(main.globalAllocator, .server); self.inv._deinit(main.globalAllocator, .server);
self.inv._items.len = 0; self.inv._items.len = 0;
self.source = .alreadyFreed;
} }
fn addUser(self: *ServerInventory, user: *main.server.User, clientId: u32) void { fn addUser(self: *ServerInventory, user: *main.server.User, clientId: u32) void {
@ -253,6 +254,7 @@ pub const Sync = struct { // MARK: Sync
} }
}, },
.playerInventory, .other => {}, .playerInventory, .other => {},
.alreadyFreed => unreachable,
} }
const inventory = ServerInventory.init(len, typ, source); const inventory = ServerInventory.init(len, typ, source);
inventories.items[inventory.inv.id] = inventory; inventories.items[inventory.inv.id] = inventory;
@ -687,6 +689,7 @@ pub const Command = struct { // MARK: Command
data.append(@intFromEnum(self.source)); data.append(@intFromEnum(self.source));
switch(self.source) { switch(self.source) {
.playerInventory, .sharedTestingInventory, .other => {}, .playerInventory, .sharedTestingInventory, .other => {},
.alreadyFreed => unreachable,
} }
} }
@ -701,6 +704,7 @@ pub const Command = struct { // MARK: Command
.playerInventory => .{.playerInventory = {}}, .playerInventory => .{.playerInventory = {}},
.sharedTestingInventory => .{.sharedTestingInventory = {}}, .sharedTestingInventory => .{.sharedTestingInventory = {}},
.other => .{.other = {}}, .other => .{.other = {}},
.alreadyFreed => unreachable,
}; };
Sync.ServerSide.createInventory(user.?, id, len, typ, source); Sync.ServerSide.createInventory(user.?, id, len, typ, source);
return .{ return .{
@ -1080,11 +1084,13 @@ pub const Command = struct { // MARK: Command
}; };
const SourceType = enum(u8) { const SourceType = enum(u8) {
playerInventory = 0, alreadyFreed = 0,
sharedTestingInventory = 1, playerInventory = 1,
sharedTestingInventory = 2,
other = 0xff, // TODO: List every type separately here. other = 0xff, // TODO: List every type separately here.
}; };
const Source = union(SourceType) { const Source = union(SourceType) {
alreadyFreed: void,
playerInventory: void, playerInventory: void,
sharedTestingInventory: void, sharedTestingInventory: void,
other: void, other: void,