Fix crash when the chat window gets a message before the GUI finished initializing.

fixes #649
This commit is contained in:
IntegratedQuantum 2025-03-03 20:24:15 +01:00
parent b50ffa5ea7
commit 57d32338fb

View File

@ -38,6 +38,24 @@ var fadeOutEnd: u32 = 0;
pub var input: *TextInput = undefined; pub var input: *TextInput = undefined;
var hideInput: bool = true; var hideInput: bool = true;
pub fn init() void {
history = .init(main.globalAllocator);
expirationTime = .init(main.globalAllocator);
messageQueue = .init(main.globalAllocator, 16);
}
pub fn deinit() void {
for(history.items) |label| {
label.deinit();
}
history.deinit();
while(messageQueue.dequeue()) |msg| {
main.globalAllocator.free(msg);
}
messageQueue.deinit();
expirationTime.deinit();
}
fn refresh() void { fn refresh() void {
if(window.rootComponent) |old| { if(window.rootComponent) |old| {
old.verticalList.children.clearRetainingCapacity(); old.verticalList.children.clearRetainingCapacity();
@ -69,25 +87,20 @@ fn refresh() void {
} }
pub fn onOpen() void { pub fn onOpen() void {
history = .init(main.globalAllocator);
expirationTime = .init(main.globalAllocator);
messageQueue = .init(main.globalAllocator, 16);
historyStart = 0;
fadeOutEnd = 0;
input = TextInput.init(.{0, 0}, 256, 32, "", .{.callback = &sendMessage}); input = TextInput.init(.{0, 0}, 256, 32, "", .{.callback = &sendMessage});
refresh(); refresh();
} }
pub fn onClose() void { pub fn onClose() void {
for(history.items) |label| { while(history.popOrNull()) |label| {
label.deinit(); label.deinit();
} }
history.deinit();
while(messageQueue.dequeue()) |msg| { while(messageQueue.dequeue()) |msg| {
main.globalAllocator.free(msg); main.globalAllocator.free(msg);
} }
messageQueue.deinit(); expirationTime.clearRetainingCapacity();
expirationTime.deinit(); historyStart = 0;
fadeOutEnd = 0;
input.deinit(); input.deinit();
window.rootComponent.?.verticalList.children.clearRetainingCapacity(); window.rootComponent.?.verticalList.children.clearRetainingCapacity();
window.rootComponent.?.deinit(); window.rootComponent.?.deinit();