Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly determine the game when cloning instances #3478

Merged
merged 4 commits into from
Jan 1, 2022

Conversation

DasSkelett
Copy link
Member

@DasSkelett DasSkelett commented Nov 17, 2021

Problem

A user reported a problem when trying to clone a KSP instance, they're getting a Clone failed: Object reference not set to an instance of an object error.
We couldn't quite figure out what the user was doing exactly, the messages were kinda vague:

I remember I was messing around with the specific path, and I changed it, but the changes didn't show up, so I figured it hadn't saved my changes or something

But after looking at the clone UI logic, these lines stood out as a possible cause for a NRE:

GameInstance sourceInstance = manager.Instances.Values
.FirstOrDefault(i => i.GameDir() == textBoxClonePath.Text);
GameInstance instanceToClone = new GameInstance(
sourceInstance.game,
textBoxClonePath.Text,
"irrelevant",
user
);

They were refactored in #3223 and didn't account for the possibility of a path being entered that didn't already belong to a known instance, which would result in a null sourceInstance.

Changes

The underlying issue that forced this instance lookup was that we didn't have a good way to determine the game of the instance to clone.
In GameInstanceManager.AddInstance() we already had a basic layout for this, but it was missing the option to prompt the user to choose between multiple games if it detected multiple potential ones.

This logic is now moved into a new DetermineGame() method, which calls User.RaiseDelectionDialog in the aforementioned case.

Both the CloneFake dialog and the AddInstance button use the new DetermineGame() method.

For testing you can simply copy KerbalSpaceProgram.cs, rename the file and class, and add it to GameInstanceManager.knownGames to force multiple games to be detected.

@DasSkelett DasSkelett added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Pull request labels Nov 17, 2021
@HebaruSan

This comment has been minimized.

@DasSkelett
Copy link
Member Author

Ah, that's why it's passed to AddInstance(). So going to pass it to DetermineGame() as well, and try to leave a comment for the User field, maybe it helps the next time.

@DasSkelett
Copy link
Member Author

I just got the idea that we could reassign the User property of the GameInstanceManager at start-up of the GUI instead, and eliminate the problem once and for all.
Do you see any pitfall that we could hit when we do this?

@HebaruSan

This comment has been minimized.

@HebaruSan

This comment has been minimized.

@HebaruSan

This comment has been minimized.

@HebaruSan

This comment has been minimized.

@HebaruSan
Copy link
Member

One more update, it's weird that the instance list shows that we know each instance's game, but then when we go to clone them we may prompt the user. Pushed a commit to make the prompting a fallback if we can't get the game from the instance (i.e., if the paths don't match).

Copy link
Member

@HebaruSan HebaruSan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me now, but in case you want to make some more changes, I'll wait a couple of days before merging it.

@HebaruSan HebaruSan merged commit e4a7ea3 into KSP-CKAN:master Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants