Skip to content

Commit

Permalink
Fix crash on startup (issue shpaass#82) when no project is previously…
Browse files Browse the repository at this point in the history
… selected.

This bug was introduced in shpaass@8f1e04e 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.
  • Loading branch information
jeady committed Apr 5, 2024
1 parent aa077c8 commit 2961fe8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions YAFC/Windows/WelcomeScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 2961fe8

Please sign in to comment.