Jump to content

Part Module Creates Null Object Refference Error and Destroys Kerbin On Launch


Recommended Posts

EXC 09:24:04.932] NullReferenceException: Object reference not set to an instance of an object

Whenever I launch a part with the following module, procedural parts module, and the procedural shapes module the above error is thrown. Any ideas on how to fix?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using ProceduralParts;

namespace ProceduralTech
{
public class ProceduralCabin : PartModule
{
[KSPField(guiActiveEditor=true)]
float cabinVolume;
[KSPField(guiActiveEditor=true)]
int crewSize;
PartModuleList modules;
ProceduralPart rootStreach;
ProceduralAbstractShape rootShape;
public float CrewDensity;
public float MassDensity;

public override void OnStart(StartState state) {
modules = part.Modules;
for (int i = 0; i < modules.Count; i++) { //find the procedural part module
if (modules [i].ClassName == "ProceduralPart") {
rootStreach = (ProceduralPart)modules [i];
}
}
rootShape = rootStreach.CurrentShape;
// print ("CD = " + CrewDensity.ToString ());
// print ("bla = " + bla.ToString());
}
public void Update() {
if (HighLogic.LoadedSceneIsEditor) {
cabinVolume = rootShape.Volume;
// print ((cabinVolume / CrewDensity).ToString());
crewSize = (int)(cabinVolume / CrewDensity);
part.CrewCapacity = crewSize;
part.mass = cabinVolume / MassDensity;
}
}
public override void OnLoad(ConfigNode ownNode) {
CrewDensity = float.Parse (ownNode.GetValue ("CrewDensity"));
MassDensity = float.Parse (ownNode.GetValue ("MassDensity"));
// print ("[Debug] CrewDensity = " + CrewDensity.ToString());
// print ("[Debug] MassDensity = " + MassDensity.ToString());
}
}
}

Link to comment
Share on other sites

Hard to tell if you don't post the whole exception (in the outputlog.txt) but most likely one of :

- in OnStart you don't check if rootStreach returned a value

- in Update you don't check if rootShape is set

Link to comment
Share on other sites

It works fine in the VAB, where both variables are being used. It should also be noted that, while crewSize works correctly, part.crewCapacity isn't being correctly shown in the crew selection tab of the VAB.

Anyone know a good file hositing site for the KSP.log

Edited by K3achas
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...