From 2961fe8a25155807a653fe7118dce4dcc17af376 Mon Sep 17 00:00:00 2001 From: James Eady Date: Fri, 5 Apr 2024 16:44:25 -0400 Subject: [PATCH] Fix crash on startup (issue #82) when no project is previously selected. This bug was introduced in https://github.com/have-fun-was-taken/yafc-ce/commit/8f1e04e5be9bd9f63452fd736d1ccf167b14bc0d by changing `struct RecentProject` to `class ProjectDefinition`. By making this type a reference, the default value is now null, instead of an object with all fields set to default, which leads to crashes when it is dereferenced. This fix makes the SetProject() function accept null as an arugment and then configures all variables as they would have been before. This continues to run the intialization code. Alternatively, we could skip the call to SetProject() entirely -- with my limited understanding of the code base, I don't know if that's safe or not. --- YAFC/Windows/WelcomeScreen.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/YAFC/Windows/WelcomeScreen.cs b/YAFC/Windows/WelcomeScreen.cs index 024ef06f..840b27b5 100644 --- a/YAFC/Windows/WelcomeScreen.cs +++ b/YAFC/Windows/WelcomeScreen.cs @@ -280,10 +280,18 @@ private void BuildPathSelect(ImGui gui, ref string path, string description, str } private void SetProject(ProjectDefinition project) { - expensive = project.expensive; - modsPath = project.modsPath ?? ""; - path = project.path ?? ""; - dataPath = project.dataPath ?? ""; + if (project != null) { + expensive = project.expensive; + modsPath = project.modsPath ?? ""; + path = project.path ?? ""; + dataPath = project.dataPath ?? ""; + } + else { + expensive = false; + modsPath = ""; + path = ""; + dataPath = ""; + } if (dataPath == "" && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string possibleDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Steam/steamApps/common/Factorio/data"); if (FactorioValid(possibleDataPath)) {