From 657daafec8ebd7d3d03e1109b4d1ec49577bac17 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Fri, 17 Oct 2025 22:58:50 +0200 Subject: [PATCH] Fix crash after reading saved credentials for first time Signed-off-by: AnErrupTion --- src/main.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index ab04dfc..5962aac 100644 --- a/src/main.zig +++ b/src/main.zig @@ -250,6 +250,16 @@ pub fn main() !void { .session_index = session_index, }); } + + // If no save file previously existed, fill it up with all usernames + if (saved_users.user_list.items.len > 0) break :read_save_file; + + for (usernames.items) |user| { + try saved_users.user_list.append(allocator, .{ + .username = user, + .session_index = 0, + }); + } } var log_file: std.fs.File = undefined; @@ -446,7 +456,10 @@ pub fn main() !void { // Load last saved username and desktop selection, if any if (config.save) { - if (saved_users.last_username_index) |index| { + if (saved_users.last_username_index) |index| load_last_user: { + // If the saved index isn't valid, bail out + if (index >= saved_users.user_list.items.len) break :load_last_user; + const user = saved_users.user_list.items[index]; // Find user with saved name, and switch over to it