Fix some problems with window closing and the delete world confirmation window.

Seems relevant for #809
This commit is contained in:
IntegratedQuantum 2024-12-05 22:05:08 +01:00
parent fd478e2b99
commit c495e8406c
2 changed files with 11 additions and 12 deletions

View File

@ -70,8 +70,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
fn executeCommands() void {
mutex.lock();
defer mutex.unlock();
while(commands.popOrNull()) |command| {
const commands_ = main.stackAllocator.dupe(Command, commands.items);
defer main.stackAllocator.free(commands_);
commands.clearAndFree();
mutex.unlock();
for(commands_) |command| {
switch(command.action) {
.open => {
executeOpenWindowCommand(command.window);
@ -84,7 +87,6 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
}
fn executeOpenWindowCommand(window: *GuiWindow) void {
main.utils.assertLocked(&mutex);
defer updateWindowPositions();
for(openWindows.items, 0..) |_openWindow, i| {
if(_openWindow == window) {
@ -95,14 +97,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
}
}
openWindows.append(window);
mutex.unlock();
window.onOpenFn();
mutex.lock();
selectedWindow = null;
}
fn executeCloseWindowCommand(window: *GuiWindow) void {
main.utils.assertLocked(&mutex);
defer updateWindowPositions();
if(selectedWindow == window) {
selectedWindow = null;
@ -110,12 +109,10 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
for(openWindows.items, 0..) |_openWindow, i| {
if(_openWindow == window) {
_ = openWindows.swapRemove(i);
window.onCloseFn();
break;
}
}
mutex.unlock();
window.onCloseFn();
mutex.lock();
}
};
@ -369,7 +366,7 @@ pub fn closeWindowFromRef(window: *GuiWindow) void {
pub fn closeWindow(id: []const u8) void {
for(windowList.items) |window| {
if(std.mem.eql(u8, window.id, id)) {
openWindowFromRef(window);
closeWindowFromRef(window);
return;
}
}

View File

@ -18,6 +18,10 @@ const padding: f32 = 8;
var deleteWorldName: []const u8 = "";
pub fn deinit() void {
main.globalAllocator.free(deleteWorldName);
}
pub fn setDeleteWorldName(name: []const u8) void {
main.globalAllocator.free(deleteWorldName);
deleteWorldName = main.globalAllocator.dupe(u8, name);
@ -48,8 +52,6 @@ pub fn onOpen() void {
}
pub fn onClose() void {
main.globalAllocator.free(deleteWorldName);
deleteWorldName = "";
if(window.rootComponent) |*comp| {
comp.deinit();
}