Ludeon Forums

RimWorld => Bugs => Topic started by: mipen on June 14, 2015, 07:08:41 AM

Title: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: mipen on June 14, 2015, 07:08:41 AM
Having colony members that do not have a Need_Mood causes a null reference exception when the Psychic Soothe event fires. This happens here:


protected override bool StorytellerCanUseNowSub()
{
if (!base.StorytellerCanUseNowSub())
{
return false;
}
float num = 0f;
List<Pawn> list = Find.ListerPawns.PawnsInFaction(Faction.OfColony);
for (int i = 0; i < list.Count; i++)
{
num += list[i].needs.mood.CurLevel; <---Here!
}
float num2 = num / (float)list.Count;
return num2 < 0.36f;
}


Proposed solution: Add null checks to check whether the pawn has a Need_Mood
Title: Re: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: StorymasterQ on June 14, 2015, 09:47:34 PM
ALWAYS CHECK FOR NULL.

I propose renaming the Null entity. We all know a better name for null. Then, IDEs all around the world can throw a new error: "There is no object, only Zuul."
Title: Re: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: Tynan on June 16, 2015, 03:15:41 AM
This is a modding support request, right? There's no way to do this in vanilla?

FYI Storymaster, "always check for null" is actually very poor advice. All you'll do is hide bugs so they show up in subtler and harder-to-trace ways. It's best to make bugs obvious immediately, by throwing a null ref exception if appropriate.
Title: Re: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: StorymasterQ on June 16, 2015, 03:27:11 AM
Quote from: Tynan on June 16, 2015, 03:15:41 AM
FYI Storymaster, "always check for null" is actually very poor advice. All you'll do is hide bugs so they show up in subtler and harder-to-trace ways. It's best to make bugs obvious immediately, by throwing a null ref exception if appropriate.

Yes, that's what I meant. Check for null, and when they show up throw a ZuulRefException as I mentioned.
Title: Re: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: mipen on June 16, 2015, 10:16:01 PM
Yeah I guess it is for modding, though it's caused by simply changing the intelligence to ToolUser which stops the pawn from being given a mood need
Title: Re: [BUG] (Alpha 11) Psychic soothe throws null ref exception when no Need_Mood
Post by: Tynan on June 18, 2015, 06:27:36 PM
I can't support this for now. It's not just the psychic soothe, that's the the first of dozens of places that would break if you had a colonist who wasn't Humanlike.

I'm afraid non-Humanlike colonists aren't officially supported by now. When they are (e.g. pets) they'll be a different class of pawns associated with the colony, not "real" colonists. Sorry my man.