Jump to content

NRE in ScenarioRunner.MoveNext


Recommended Posts

Hi guys, I'm seeing a strange issue.

I have this simple ScenarioModule.

It throws a NRE immediately after Awake() finishes: using darklight's ExceptionDetector, I see that the exception is thrown in ScenarioRunner.MoveNext, but I have no idea what I'm doing wrong... has anybody seen something like this?

Link to comment
Share on other sites

Is there any more of the stack trace to go on? You usually see this kind of exception when something bad has happened in ScenarioModule.OnLoad and it's doubly-bad because any ScenarioModule that comes after yours won't be loaded.

At a guess and with no other info, I'd say the ConfigNode you tried to load in ScienceFunding.GetConfig doesn't exist or doesn't have a node called SCIENCE_FUNDING_SETTINGS -- you try to use it immediately after loading it without checking that the file exists and without checking that it was loaded or has such a node, and it's out of your general try...catch so a NRE in there will unwind back to the caller (ScenarioRunner)

Link to comment
Share on other sites

You say it is thrown after the Awake() method on your scenario module. I can't find the code where your scenario is loaded by KSP, doesn't it need a [scenario] attribute of some sort, the same way the [KSPAddon] works?

The reason I ask that is that if the .MoveNext is throwing a nullref, somethings gone wrong in the "loaded scenarios" list because it can't move from your scenario to the next, and I wonder if how you are loading your scenario is generating issues.

D.

Link to comment
Share on other sites

It's not necessary to use the scenario attribute, you can add your Scenario Module to the list manually, but using the attribute is the simplest way.

And even if using OnAwake fixes the problem you should still make sure that absolutely any exceptions in the loading process be handled. Blowing up the Scenario Module loading process is about the worst thing a mod can do since it cascades down to all subsequent Scenario Modules.

Link to comment
Share on other sites

It's not necessary to use the scenario attribute, you can add your Scenario Module to the list manually, but using the attribute is the simplest way.

And even if using OnAwake fixes the problem you should still make sure that absolutely any exceptions in the loading process be handled. Blowing up the Scenario Module loading process is about the worst thing a mod can do since it cascades down to all subsequent Scenario Modules.

Agree 100% - having try/catch blocks in the OnSave, OnLoad (and anywhere else that gets invoked from Squad code) in the ScenarioModules, contracts (and anywhere else where mod code can get loaded) is pretty much essential to not stomp on each other stuff when things go wrong.

Or perhaps it's time we get our resident Squad assistant (contractor? collaborator? I'm not really sure the right term) to push in a change to get the exception handling logic put in the places that can potentially call into mod code (particularly from a loop) so that mods can't inadvertently cause havok. ;)

Link to comment
Share on other sites

Or perhaps it's time we get our resident Squad assistant (contractor? collaborator? I'm not really sure the right term) to push in a change to get the exception handling logic put in the places that can potentially call into mod code (particularly from a loop) so that mods can't inadvertently cause havok. ;)

This would be wonderful! It's been bad enough that KCT now has a check for if the OnLoad process fails (due to KCT or another mod). A vast majority of the reports I get regarding that error check are from other mods encountering an issue during OnLoad which then makes KCT not get a chance to load. Occasionally they're KCT's fault, so I should probably increase my error handling to catch those. :P Contract Configurator used to do it pretty badly ;) but has since improved substantially, but it really doesn't help either that the Contracts system completely explodes if it stubs its toe (I'm pretty sure the Contracts system is made of nitroglycerin).

OnLoad and Contracts are the two places I'd like to see better error handling in Stock. It's also on us modders to A) not make code that has errors and B) have proper error handling in sensitive areas, but not having those areas be that sensitive to minor issues would be nice ;)

Link to comment
Share on other sites

:P Contract Configurator used to do it pretty badly ;)

Oh this is so true - I was once so naive! On top of the error handling I now have that prevents other mods from getting borked, I also have pop up errors for the *really* bad stuff (in particular, anything that is potentially save breaking for the player).

Link to comment
Share on other sites

I think you want to use OnAwake, not Awake...

Ah, that was it :)

Originally it was a MonoBehaviour, so I forgot to update it to override OnAwake when I switched to a scenario.

I didn't congratulate you on the promotion yet, by the way: great job Nathan! :)

Thanks everyone for helping!

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.

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.

×
×
  • Create New...