Unhandled Reference for my mod

A null value was encountered where this forum description was required.
Post Reply
User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Unhandled Reference for my mod

Post by JunJayMdM » November 8th, 2012, 4:47 pm

Error Trap just logged an Unhandled Reference, and it's about my Online Center mod, hence I'm more than interested in what this could mean :)

I'm uploading it as I type.

P.S. The interaction mentioned in the error, was being used by a Sim, then I saved and when I reloaded the game, the Sim completed the interaction normally, while Error Trap reported the script error.

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » November 8th, 2012, 7:48 pm


Your "Relationships" list is storing a reference to the Sim object for "Keenan Pulliam".

However that object has since been deleted from the game. "Keenan Pulliam" may still exist as a sim, but the object being stored in the list is not valid any longer.

If you really need to persist a list of "Sim" objects via your interaction, then it is not really a big deal. Though I'm not sure what your code does if the user chooses that particular sim now that they are no longer valid. :)

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » November 8th, 2012, 7:50 pm


Personally, I would go with a list of SImDescription objects instead, and use the "CreatedSim" function to retrieve the "Sim" from the selection.

SimDescription objects tend to be longer lasting. :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » November 8th, 2012, 7:59 pm

Interesting, I use the same method EA uses in their "Chat" interaction. But I'm thinking the problem lies in this :

<!-- ws:start:WikiTextCodeRule:0:
<pre class="text"> if (this.Relationships == null)<br/> {<br/> this.Relationships = new List&lt;Sim&gt;();<br/> }<br/> else<br/> {<br/> this.Relationships.Clear();<br/> }<br/> this.Relationships.AddRange(PlumbBookHandler.FindRelationships(this.Actor));<br/></pre>
-->
<style type="text/css"><!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.text {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">&nbsp;
if (this.Relationships == null)
{
this.Relationships = new List<Sim>();
}
else
{
this.Relationships.Clear();
}
this.Relationships.AddRange(PlumbBookHandler.FindRelationships(this.Actor));
&nbsp;</pre>


It's the first time I saw this error and the last thing I changed was this one, where I keep the list and just clear it when done.

So, you think I should use a List<SimDescription> instead? I will give it a try, thanks :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » November 8th, 2012, 8:08 pm

Just to make sure :

<!-- ws:start:WikiTextCodeRule:0:
<pre class="text"> foreach (Sim otherSim in actors)<br/> {<br/> if (Relationship.Get(actor, otherSim, false) != null)<br/> {<br/> SimDescription otherDesc = otherSim.SimDescription as SimDescription;<br/> if (otherDesc != null &amp;&amp; otherDesc.CreatedSim != null &amp;&amp; !list.Contains(otherDesc))<br/> {<br/> list.Add(otherDesc);<br/> }<br/> }<br/> }<br/></pre>
-->
<style type="text/css"><!--
/**
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
*/
.text {font-family:monospace;}
.text .imp {font-weight: bold; color: red;}
.text span.xtra { display:block; }

-->
</style><pre class="text">&nbsp;
foreach (Sim otherSim in actors)
{
if (Relationship.Get(actor, otherSim, false) != null)
{
SimDescription otherDesc = otherSim.SimDescription as SimDescription;
if (otherDesc != null && otherDesc.CreatedSim != null && !list.Contains(otherDesc))
{
list.Add(otherDesc);
}
}
}
&nbsp;</pre>


It's just a portion but is this what you meant?

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » November 8th, 2012, 8:24 pm


ErrorTrap does not see "code", it sees the [Persistable] objects you save to the save-file.

So it sees the information you store in your classes member fields. In this case the "Relationships" field you mentioned in the second last post.

A "List<SimDescription> Relationships" member field would be preferable in my mind. Should save you running into logs from ErrorTrap.

Personally, I'm not a huge fan of any reference to a "Sim" object EA uses, and they like to use them a lot in their code.

"Sim" objects are deleted far too readily by the game (they are deleted whenever a homeless sim "goes home", and any time a sim is hard-reset by my mods), and are always popping up in referencing logs. :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » November 8th, 2012, 8:34 pm

Ah cool, well I guess I'll keep in mind this, right now I'm converting it to List<SimDescription>. It's a good thing I used a List<MiniRelationship> for home world sims when on Vacation then :)

Thanks for the info, it was precious :)

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » January 9th, 2013, 5:25 pm


(retained)

Post Reply