Skip to content

Commit

Permalink
Fix some problems with window closing and the delete world confirmati…
Browse files Browse the repository at this point in the history
…on window.

Seems relevant for #809
  • Loading branch information
IntegratedQuantum committed Dec 5, 2024
1 parent fd478e2 commit c495e84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/gui/gui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -95,27 +97,22 @@ 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;
}
for(openWindows.items, 0..) |_openWindow, i| {
if(_openWindow == window) {
_ = openWindows.swapRemove(i);
window.onCloseFn();
break;
}
}
mutex.unlock();
window.onCloseFn();
mutex.lock();
}
};

Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/windows/delete_world_confirmation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -48,8 +52,6 @@ pub fn onOpen() void {
}

pub fn onClose() void {
main.globalAllocator.free(deleteWorldName);
deleteWorldName = "";
if(window.rootComponent) |*comp| {
comp.deinit();
}
Expand Down

0 comments on commit c495e84

Please sign in to comment.