Skip to content

Windows error after KSP reinstall: Object reference not set to an instance of an object #2443

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

Closed
Topperfalkon opened this issue May 13, 2018 · 14 comments
Assignees
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN

Comments

@Topperfalkon
Copy link

Topperfalkon commented May 13, 2018

Background

CKAN Version:
1.25.1

KSP Version:
1.4.3.2152

Operating System:
Windows 10

Have you made any manual changes to your GameData folder (i.e., not via CKAN)?
KSP has been recently reinstalled

Problem

What steps did you take in CKAN?
(After reinstalling KSP)

  1. Open CKAN (running from Download folder, not KSP folder)
  2. CKAN notifies me that the KSP version has been updated, and raises the Compatible Ksp Versions window
  3. Click Save

What did you expect to happen?
I expect my preferences to be saved

What happened instead?
An error is thrown: Object reference not set to an instance of an object

Workaround
Moving ckan.exe to KSP's root folder seems to have resolved the issue

CKAN error codes (if applicable):
N/A, but see Windows exception message below

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at CKAN.KSP.SaveCompatibleVersions()
   at CKAN.CompatibleKspVersionsDialog.SaveButton_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
@HebaruSan
Copy link
Member

Possibly caused by Version() being null here:

CKAN/Core/KSP.cs

Lines 123 to 134 in 5c5cb60

private void SaveCompatibleVersions()
{
CompatibleKspVersionsDto compatibleKspVersionsDto = new CompatibleKspVersionsDto();
compatibleKspVersionsDto.VersionOfKspWhenWritten = Version().ToString();
compatibleKspVersionsDto.CompatibleKspVersions = _compatibleVersions.Select(v => v.ToString()).ToList();
String json = JsonConvert.SerializeObject(compatibleKspVersionsDto);
File.WriteAllText(CompatibleKspVersionsFile(), json);
this.VersionOfKspWhenCompatibleVersionsWereStored = Version();
}

That can happen if we can't find buildID.txt or readme.txt in the game dir.

... and indeed, I can reproduce this if I:

  1. Have exactly one game instance
  2. Set at least one additional compatible version in the compatible versions dialog
  3. Remove buildID.txt and readme.txt, without removing the KSP folder or the CKAN folder
  4. Launch the GUI

@HebaruSan
Copy link
Member

@Topperfalkon, thanks for the bug report. What does your reinstall process look like? It looks like you deleted some of the game files but not the main game folder, and then installed the new version somewhere else, since the version info is missing but the CKAN configuration data is still there. We can work on making this code more robust, but you should be able to work around the problem in the meantime by deleting the (old!) main game folder.

@Topperfalkon
Copy link
Author

I uninstalled then reinstalled through Steam's UI. I've noticed that Steam doesn't always properly delete folders when you tell it to uninstall games, and it doesn't always detect certain files are missing either.

@HebaruSan
Copy link
Member

Interesting. Can you try the validate local files trick in Steam to see if that helps? If it puts the buildID.txt file back, then that should help.

@HebaruSan HebaruSan self-assigned this May 13, 2018
@HebaruSan HebaruSan added Pull request Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN labels May 13, 2018
@Topperfalkon
Copy link
Author

Topperfalkon commented May 13, 2018

I tried deleting buildID.txt (well, renaming) and validating files, but seems to have brought the file back correctly.

@HebaruSan
Copy link
Member

So the file was there before? That should make the reported error impossible.

After it brought it back, does the error still happen?

@Topperfalkon
Copy link
Author

It's still happening if I open the copy of CKAN that isn't in the install folder, but not the one that's in the KSP root folder. I'm not sure why there's a difference, given that they were literally the same executable

@HebaruSan
Copy link
Member

Hmm, that suggests there are two different game folders involved here; presumably the one whose root folder you're looking at is the one in Steam, and CKAN thinks it knows about some other one.

Can you post a screenshot of the Select KSP Install window (via the File menu)?

image

@Topperfalkon
Copy link
Author

image

This is from the working ckan.exe in the KSP folder, the other executable is being blocked from proceeding by this error, so I can't tell if it knows about a different install

@HebaruSan
Copy link
Member

Hmm, that "NONE" shouldn't look like that; it should have the actual version of the game, like this:

image

(My previous screenshot said NONE because I had deleted the buildID.txt and readme.txt files.)

All signs still point to the "working" version being in a folder other than your main Steam folder. Can you show a screenshot of that folder?

@Topperfalkon
Copy link
Author

Ah!

You're right, the working installation is on my E: drive, though it's a bit weird that CKAN is working fine there, even though it's pointing to a different install. Removing the GameData folder from the old install caused the non-working CKAN executable to prompt me for KSP's location again, and is now working. How weird.

I must have reinstalled it to the E: drive instead of the C: drive when I uninstalled it, but Steam clearly didn't clean up the previous installation correctly.

@HebaruSan
Copy link
Member

Cool! Glad you got it working!

though it's a bit weird that CKAN is working fine there

Yeah, CKAN has a few features that make this confusing. It will treat its current directory as a KSP folder if it contains GameData, without adding it to the list in the "Select KSP Install" window. So that's what it was doing when you ran it from the folder on E:.

Then as a fallback it tries to find your Steam folder, which is added to the list and if that works. And once an instance is in the list, it stays there until you remove it. So that's what it was using when you ran it from the download folder.

@Topperfalkon
Copy link
Author

Cool, that makes a lot more sense now.

Would be nice to have a bit more hardening for handling edge cases like this. Perhaps forcing the Select KSP Install window to display if it can't find the buildID.txt?

Also teaches me to pay more attention when I'm reinstalling things on Steam that they're going to the right place!

Sorry, something went wrong.

@HebaruSan
Copy link
Member

Would be nice to have a bit more hardening for handling edge cases like this. Perhaps forcing the Select KSP Install window to display if it can't find the buildID.txt?

Yeah, I agree. Added that to #2444.

Sorry, something went wrong.

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

No branches or pull requests

2 participants