Jump to content

I've broken pause


Recommended Posts

When I press escape I am getting an error message. The puase menu appears but time continues. I broke it a while ago while developing a plugin but didn't notice.

Can anyone suggest something I might have done wrong?

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

Game Paused!

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

NullReferenceException: Object reference not set to an instance of an object

at Part.partPause () [0x00000] in <filename unknown>:0

at EventVoid.Fire () [0x00000] in <filename unknown>:0

at FlightDriver.SetPause (Boolean pauseState) [0x00000] in <filename unknown>:0

at PauseMenu.Display () [0x00000] in <filename unknown>:0

at PauseMenu.Update () [0x00000] in <filename unknown>:0

Link to comment
Share on other sites

My last desperate resort is usually this:

uncomment your mod, section for section, and see where it's caused..

if the causeing section is commented, the error is gone - it's as simple as that - but takes time..

but actually, I don't believe this is the first error in that log..

..there must be (in my logic) an other one before that..

have an other look - not all log errors are easely spotted..

Link to comment
Share on other sites

I have narrowed down the cause

When loading my mod I am calling vessel.load() on a list of vessels in order to get some information on them. I extract the information and call vessel.unload() but it seems that something happens on the load which means that an exception is thrown when the game is paused.

Link to comment
Share on other sites

NullReferenceException: Object reference not set to an instance of an object

at Part.partPause () [0x00000] in <filename unknown>:0

at EventVoid.Fire () [0x00000] in <filename unknown>:0

at FlightDriver.SetPause (Boolean pauseState) [0x00000] in <filename unknown>:0

at PauseMenu.Display () [0x00000] in <filename unknown>:0

at PauseMenu.Update () [0x00000] in <filename unknown>:0

Note the Part.partPause as the first line. Something running in that method in a part module is failing and stopping the OnPause code from executing and so KSP never reaches the "stop time" code as it aborts before then.

As this is in plugin help, I'm assuming you are trying to develop code running on pause. Either comment that code out or wrap it in a try/catch block so that the KSP does not stop running the pause code.

It is not good coding practice in general, but for KSP mods I recommend wrapping everything in a try/catch block because of this. That way when your mod fails, you don't crash KSP because KSP will keep running its own code instead of hitting the nullRef error and stopping.

It also allows you to error trap if you set it up correctly.


onPause method()
{
string ErrLine = "1";
try
{
codeLine1
ErrLine = "2";
codeLine2
ErrLine = "3";
codeLine3
etc.
}
catch(Exception e)
{
print("OnPause error " + ErrLine + " e);
}
}

That way if KSP hits a nullref in your code, it will print the message to the log along with which line it hit the error on. It also keeps executing the rest of the code instead of stopping so you don't cause a cascade error somewhere else in KSP.

D.

Link to comment
Share on other sites

I'm not trying to do anything on pause but I think it is because I was holding a reference to a PartModule. I can think of a way round it but I need to be able to get the details to start with by loading the vessel.

Ohh, this is new

NullReferenceException

at (wrapper managed-to-native) UnityEngine.Transform:INTERNAL_get_position (UnityEngine.Vector3&)

at UnityEngine.Transform.get_position () [0x00000] in <filename unknown>:0

at Vessel.recurseCoMs (.Part part) [0x00000] in <filename unknown>:0

at Vessel.findLocalCenterOfMass () [0x00000] in <filename unknown>:0

at ProtoVessel..ctor (.Vessel VesselRef) [0x00000] in <filename unknown>:0

at Vessel.Unload () [0x00000] in <filename unknown>:0

Edited by tomf
Link to comment
Share on other sites

I have narrowed down the cause

When loading my mod I am calling vessel.load() on a list of vessels in order to get some information on them. I extract the information and call vessel.unload() but it seems that something happens on the load which means that an exception is thrown when the game is paused.

ok I see..

try this..

foreach(Vessel v in FlightGlobals.Vessels)

{

foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)

{

if (p.partRef.name == "what ever")

{

//do stuff

}

}

}

you don't need to load the vessel to get the parts (not sure about part modules though)

Link to comment
Share on other sites

It is the modules that I want, if I try getting the modules for a protopartsnapshot I get null pointer errors.

it might be worth a try, to include in this loop, some code to "activate" the "part" instead of the vessel..

I have not tested that - but probbably you can fool the loader that way..

Link to comment
Share on other sites

Any idea of how to do it? I explicity want to get at an object which is going to be created inside the partmodule

Calling ProtoSnapshotPart.load gets me this.

ArgumentOutOfRangeException: Argument is out of range.

Parameter name: index

at System.Collections.Generic.List`1[Part].get_Item (Int32 index) [0x00000] in <filename unknown>:0

at ProtoPartSnapshot.Load (.Vessel vesselRef, Boolean loadAsRootPart) [0x00000] in <filename unknown>:0

Link to comment
Share on other sites

Ok by looking at ProtoPartModuleSnapshot.moduleValues I can get the persisted information about this instance of a partmodule, but what I still can't do is get the generic KSPField value for all instances of that module for that part. Any ideas?

Link to comment
Share on other sites

Ok by looking at ProtoPartModuleSnapshot.moduleValues I can get the persisted information about this instance of a partmodule, but what I still can't do is get the generic KSPField value for all instances of that module for that part. Any ideas?

part.activate = ;

part.ActivatesEvenIfDisconnected = ;

part.active = ;

part.drawStats = ;

part.enabled = ;

part.Fields = ;

part.force_activate = ;

part.LoadModule = ;

part.partInfo = ;

part.partInfo.moduleInfo = ;

part.partInfo.moduleInfos = ;

part.partInfo.partPrefab = ;

part.partInfo.partPrefab.Fields = ;

not really "ideas" but the above is what I would try..

the bold ones are those I think have best chances..

Link to comment
Share on other sites

In case someone finds this thread inthe future, What I have ended up doing is

looping for each ProtoPartSnapshot

using ProtoPartSnapshot.partInfo.partPrefab to get a prototype for a part complete with it's modules with their default properties

finding the module that I want

finding the ProtoPartModuleSnapshot in ProtoPartSnapshot.modules

getting the specific config for this module instance with ProtoPartModuleSnapshot.moduleVaules

using OnLoad to load them into me Module

Reading all the info I want out of the initialized module.

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