Jump to content
  • 0

How to debug an error on startup?



Sometimes when you have a lot of mods and you do some updating, a mod will throw an error on startup.  Sometimes these errors are not due to said mod but a different one.  While @linuxgurugameris great at always helping people, I feel bad taking their time.  So I am wondering, could we get an explainer on how to find what is actually causing a problem so we can try and fix it ourselves and let @linuxgurugamer be a gamer?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

If the game crashes/freezes, then the last items in the log will say what it was doing when it happened.

If chasing NREs or other errors, the log usually says “null ref exception” or “error” on the entry and mentions a load of hex code and the name of the class the error was contained in (which doesn’t always relate to the recognised name of the mod either).

Other times it’s experience of knowing what mods might be conflicting as logs seem normal. Sometimes it takes hours and hours of testing as the answer is hidden away somewhere in an obscure line.

Of course, to solve it yourself you would probably need to find and decipher (understand) the source code and even then you’d need to contact the mod maker for them to change or clone/edit/do pull request with fixed code, which they may just discard anyway.

When you make a mod (or code anything) you expect to have to deal with this sort of thing, although I understand your concerns for LGG and his 5000 mods :D

Link to comment
Share on other sites

  • 0

Did you come across a specific issue you want to solve? That would allow us to explain the process using that issue as an example.

Depending on the error type, you have to look up the game logs and/or logs created my other mods (MM, Kopernicus,...) and/or the MM config cache.
Then you have to locate the error and try to figure out:

1. what exactly does the error tells you? (nullRef, NaN, Array out of bounds,...)
2. which mod throws the exception/error? (for example by looking at the stacktrace which usually contains some more or less obvious hints)
3. when does the mod throw the exception? (during startup, scene switch, in the editor, after clicking a specific button, ...)
4. try to replicate the issue in a fresh game install which has only that one particular mod (+dependencies) installed
5. locate the code which causes the error by looking at the stacktrace and the source code (usually found at github)
6. if you know how to code or you want to learn it, you can try to setup an development environment and try to find a solution for the issue which then can be put into a pullrequest for the mod creator to fix the bug.

Btw.: It's really useful to enable "verbose logging" in the game settings and "Flush log immediately to disc" in the debug menu (alt+F12 or ctrl + alt + F12, works also during game launch) to get the most information out of the log. You may also want to display exceptions and warnings on screen while playing to get an better idea when exactly the error happens (the error pops-up in the upper right corner then). Little warning though: if you try to track down any little exception which doesn't completely break a mod, you'll loose any time to actually play the game :P )

Short example for Kaptains Log:

The mod throws this exception:

Exception handling event onGameStateCreated in class KaptainsLog:System.NullReferenceException: Object reference not set to an instance of an object
  at KaptainsLogNamespace.KaptainsLog.InitDisplayFields () [0x00025] in <a5378a797d1349b49b3b355ebb6a1d03>:0 
  at KaptainsLogNamespace.KaptainsLog.InitOnLoad () [0x0012c] in <a5378a797d1349b49b3b355ebb6a1d03>:0 
  at KaptainsLogNamespace.Utils.LoadLogs () [0x00062] in <a5378a797d1349b49b3b355ebb6a1d03>:0 
  at KaptainsLogNamespace.KaptainsLog.onGameStateCreated (Game g) [0x00000] in <a5378a797d1349b49b3b355ebb6a1d03>:0 
  at EventData`1[T].Fire (T data) [0x000b0] in <9d71e4043e394d78a6cf9193ad011698>:0 

I hope I don't need to explain why this exception is definitely thrown by kaptains log and not any other mod ;)

So, to follow my own list:
1) it's a nullRef
2) Kaptains Log
3) The exception is in line 120054 of the log, line 120399 shows a scene switch from main menu to the spacecenter, so it's thrown in the main menu
4) I'm not going to bother with that for this example
5) The last method in the stacktrace says "KaptainsLogNamespace.KaptainsLog.InitDisplayFields ()", so I search for "InitDisplayFields" in the github repository of the mod and find this: https://github.com/linuxgurugamer/KaptainsLog/blob/9e878cc840a622eac87e36464f0a2e4456c72b40/KaptainsLog/KaptainsLog.cs#L346
6) I'm not going to load the whole thing into visual studio and try to find a solution but I can take a guess:
We are looking for an object which is referenced in this code but potentially can be null. The list of "DisplayField" is initialized in line 325 and checked against null, so that's not the issue.
Line 356 to the end of the method populates the list of displayFields, partially referencing "k14" from line 354:

KL_12 kl4 = HighLogic.CurrentGame.Parameters.CustomParams<KL_12>();

(Thanks for the "meaningful" variable name, LGG :confused: :D)
So it's either "k14" which is null or any of the referenced properties.

Fun fact: I wasn't able to replicate this issue in a reliable way, so this might be a race condition or it was just a fluke :confused:


Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...