godarklight

ExceptionDetector 1.1 [KSP ANY VERSION]

Recommended Posts

Download Links

Download from my build server (pre-KSP-1.1).

Download from my build server (version 2) (KSP-1.1).

Download from my build server (version 3) (KSP-1.3).

Download from SpaceDock.

Licence: Unlicence (Public Domain).

Source: Github

So what *is* this thing?

When a program does an invalid operation (such as dividing an integer by zero) an error called an exception is thrown.

Exceptions can easily put KSP into a bad state and random things will stop working.

This mod is a simple indicator for players to find misbehaving mods.

Pretty screenshot:

NTocwjl.png

Edited by godarklight

Share this post


Link to post
Share on other sites

How many different errors can this detect, the "divide by 0" in the example, nullrefs are implied in the title, but what else have you added ?

Share this post


Link to post
Share on other sites

Rep for you, sir! My main concern is that very few players will use this since the main benefit is to the modder (ie the benefit to the player is indirect). Still, every little bit helps!

Share this post


Link to post
Share on other sites

Well, this would be superduper usefull if it where an in game warning system. "Fatal error approaching! You have 5-4-3-2-1 seconds to press F5 or risk losing all progress since last save (2.1 hours ago)"

Share this post


Link to post
Share on other sites

@RainDreamer: Basically, the far left side of the methods that are throwing should hint at which mod it actually is (that's the namespace). I could probably do a bit of parsing and print the DLL that it comes from as well.

@Nemrav: Basically, anything that turns red in the alt+F12 debug menu.

@nightingale: I'm not actually sure what the market for this is, but it's a very simple mod and it might come in handy for someone so I threw it up here. It *might* come in handy for mod developers, but there's a very slim chance of that as most are certainly capable of their own debugging, unless they just want a really noisy exception alert :).

@1of6Billion: I'm a modder, not a future predicting miracle worker haha

Edited by godarklight
spelling...

Share this post


Link to post
Share on other sites

Nice, so much better than needing to keep the debug log up. But if I could suggest a suggestable, maybe use DateTime.Now for the timestamp just to be a bit more human readable.

Share this post


Link to post
Share on other sites
@RainDreamer: Basically, the far left side of the methods that are throwing should hint at which mod it actually is (that's the namespace). I could probably do a bit of parsing and print the DLL that it comes from as well.

Yeah, that would be lovely, because I don't actually know what is inside the DLLs of my mods at all. At least with a filename it would help much more for those who is not actually a modder. :)

Share this post


Link to post
Share on other sites
So, is there an explanation for those who are not very technologically savvy to use it to detect misbehaving mods?

A lot of people don't realise that their mods are causing errors. They make the game run slowly, and could sneakily do harm to your space program in some way or another. This mod shows you what parts of the game are causing errors.

In the screenshot, there are 194 errors happening every second! You might not notice the errors, but your game would be running much slower than normal. The next two lines show where the errors come from. The part before the dot is normally the name of the mod, or at least something close to it. If you google that part, it should lead you to the mod's source code. In the example screenshot, the two parts of the code causing errors are KSPNREDetector and ScreenMessages.

How many different errors can this detect, the "divide by 0" in the example, nullrefs are implied in the title, but what else have you added ?

It displays exceptions, which means "pretty much everything", including any new type of error that's invented in the future.

Share this post


Link to post
Share on other sites

My KSP install has become pretty crashtastic. Thank you for a tool that might help me find the offending mods.

Share this post


Link to post
Share on other sites

Very handy tool, now I know which mod gives errors and find them quicker in the log.

Share this post


Link to post
Share on other sites

@Everyone, seeing as how the tool is kind of useless at the moment, I decided to put a bit more work into it and directly point at which DLL file is causing the problem.

It correctly walks down the stack looking for the first thing that's a mod. If it doesn't find one, it blames the first method that threw, which may be stock mono, or it may be KSP or Unity.

I also moved it to a window as my Update method wasn't getting called if another mod throws (KSP loads in alphabetical order by the looks):

NTocwjl.png


using System;
using System.Collections.Generic;
using UnityEngine;

namespace KSPTest
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class MainClass : MonoBehaviour
{
bool throwState = false;
float lastThrowTime = float.NegativeInfinity;

public void Update()
{
if ((Time.realtimeSinceStartup - lastThrowTime) > .5f)
{
lastThrowTime = Time.realtimeSinceStartup;
throwState = !throwState;
if (!throwState)
{
DivideByZero();
}
else
{
ThrowKNFEMethod();
}
}
}

public void ThrowKNFEMethod()
{
Dictionary<string,string> someDictionary = new Dictionary<string, string>();
Debug.Log(someDictionary["Hello"]);
}

public void DivideByZero()
{
int a = 1;
int b = 0;
Debug.Log(a / B);
}
}
}

I used KWS from github as an example I occasionally help out there too.

You'll almost certainly want to grab this version if you're trying to diagnose an install problem :)

Edited by godarklight

Share this post


Link to post
Share on other sites

I'm undecided if I want to install this or not. My mod list is longer than my arm and I'm somewhat concerned that there might be exceptions occurring often. The only issue I'll see is that I might try too hard to fix the bugs myself, and spend more time in an IDE than in KSP!

Also, have you considered calling it ExceptionDetection? :P

Share this post


Link to post
Share on other sites

I don't know if this is a bug, but when I reload the database using ModuleManager some mods give 200+ exceptions.

Share this post


Link to post
Share on other sites

So far this has shown me that ActiveTextureManagement and MechJeb are constantly throwing exceptions, and those are a couple mods that I just can't live without. I doubt that explains the weirdness that's been happening lately, though.

I mean, decouplers constantly puffing smoke (even in the VAB) and rockets leaving their command modules behind, floating over the launchpad. What could that be?

Share this post


Link to post
Share on other sites
I don't know if this is a bug, but when I reload the database using ModuleManager some mods give 200+ exceptions.

Some modules get reinitialized on database reload in a different order than they were initialized on game startup, which causes plugins that make assumptions about what exists when their modules are initializing to throw exceptions. Many of these exceptions are harmless unless they keep KSP from finishing what it was doing, but they take up log space and the log file writes cost you performance.

It's most likely not a bug in ExceptionDetector, although you'll want to find the full stack traces in the Unity log and confirm that the decide-what-plugin-to-blame logic agrees with your own judgment.

- - - Updated - - -

So far this has shown me that ActiveTextureManagement and MechJeb are constantly throwing exceptions, and those are a couple mods that I just can't live without. I doubt that explains the weirdness that's been happening lately, though.

I mean, decouplers constantly puffing smoke (even in the VAB) and rockets leaving their command modules behind, floating over the launchpad. What could that be?

Those glitches that you mentioned tend to be triggered by TweakScale or TweakableEverything.

Share this post


Link to post
Share on other sites

Those glitches that you mentioned tend to be triggered by TweakScale or TweakableEverything.

Well darn it, I have both of those. Need them for all the procedural whatevers. Well, maybe not Tweakable Everything, and I may have accidentally turned on TweakScale's automatic mode.

Sorry for kind of turning this into a support thread, but it does demonstrate the usefulness of this ExceptionDetector mod.

Share this post


Link to post
Share on other sites

That part "DevideByZero: 54" reminds me of ye good ol' SimCity, when you shift+click on a statue "number of pigeons pooped upon: 1054". So it made me kinda lol.

Share this post


Link to post
Share on other sites

Interesting little utility here. Especially interesting is that during KSP load, this mod produces a constant stream of null ref exceptions. I wonder if it would detect it's own exceptions? hmm...

Share this post


Link to post
Share on other sites

@Nerezza: At first it was called KSPNREDetector. It's current name isn't completely terrible, and at least I didn't name this mod after myself :D

@Olympic1: Could be MM, could be the mods that depend on MM. Although that's generally not too much of a problem as you have to explicitly hit that button

@ultrasquid: If it's not a problem with MJ it *could* be a problem with something that changes the way MJ works, but the exceptions can cause

(this was hotrockets back in the day).

@undercoveryankee: Exceptions that bubble up into KSP are NOT harmless. If you throw in an Update call, all other things after that call are skipped, which causes all the strange problems. In DMP I catch and log them to prevent them bubbling up into KSP, which is slightly better than completely killing KSP with exceptions.

Also, the what-plugin-to-blame logic is "from the top of the stack trace, step through until it finds a mod. If it doesn't find one, blame the first call" (which will either by mono, unity, or KSP)

@MennoLente: The last one I played was simcity 2000. Although transport tycoon was better :P

@Gaalidas: I'd really need KSP_Data/output_log.txt, and it should definitely detect it's own exceptions. This mod hijacks the KSP.log callback, so if it's throwing it might prevent KSP.log (and alt+f12 debug) from working. This mod really should not be throwing :-/

Edited by godarklight

Share this post


Link to post
Share on other sites

This tool is quite useful to diagnose which problem or at least which mod's problem is slowing your game.

Because exception handling codes in your program are normally slower than those normal codes.

Share this post


Link to post
Share on other sites

Wow, the timing on this is perfect! I have been playing the last two days with the debug window open (Alt+F2) looking for red lines, and seeing fair amount of orange as well, of null refs flashing by. I have a lot of mods installed, and my frame rate was getting very "chunky" to say the least. I tracked down a few mods that don't play nice, and this will help immensely! Thanks godarklight!

PS - I've been using the DMP client for multiplayer about 3 months now, and I can't live without it! I do enjoy KSP offline, with a heavily modded install, but multiplayer breaks the lonely single player boredom. Now we just need more hosts with modded servers, and players to populate and support them!

Share this post


Link to post
Share on other sites

I installed this and for a while thought it wasn't working. Then I checked my log and sure enough, (almost) no exceptions!

ATM gets one at load time, and then I never see the window again. Even though I have enough mods loaded to need ATM :)

Cool mod, and proof we have an awesome modding community.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   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.