playMaker

Author Topic: Null Reference Exception only when Editor Window is open.  (Read 11336 times)

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Null Reference Exception only when Editor Window is open.
« on: April 18, 2011, 08:57:09 PM »
I've come across an odd bug that has had me stumped for a week because I couldn't work out what was actually triggering it.  I finally tracked it down and can reproduce it, but it only triggers when the editor window is open, and it doesn't trigger at all when the window is closed.

I'm pretty sure it could be related to the Broadcast Event action, as it is triggering after one of these.  The stack trace takes it back to one anyway.

The code it crashes on is here :
Code: [Select]
if (float1.Value < float2.Value)
{
        // Crashes on the next line with null ref
Fsm.Event(lessThan);
return;
}
And that is inside the DoCompare() function of the FloatCompare Action.  I've tried attaching the debugger and working through it in MonoDevelop, but everything seems to be fine there, so I'm wondering if there is something strange going on internally inside the editor, eg. the broadcast message is possibly going to un-instantiated prefabs inside the editor?  This is about that only behavior that makes sense to me right now.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Null Reference Exception only when Editor Window is open.
« Reply #1 on: April 18, 2011, 09:05:38 PM »
Thanks, I'll look into this. I'll look into the uninstantiated pefab idea - to be honest I haven't totally figured out prefab behavior in the editor yet - sometimes Unity editor code seems to see prefabs, other times it doesn't...

danien

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 4
Re: Null Reference Exception only when Editor Window is open.
« Reply #2 on: May 24, 2011, 10:56:38 PM »
I believe I have the same problem. I also have a Broadcast Event action in the state (in fact, the only action in the state) and when I close the PlayMaker Editor tab, the Unity Console log no longer shows the NullReferenceException.

NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState)
HutongGames.PlayMaker.Fsm.DoTransition (HutongGames.PlayMaker.FsmTransition transition, Boolean isGlobal)
HutongGames.PlayMaker.Fsm.ChangeState (System.String eventName)
HutongGames.PlayMaker.Fsm.Event (System.String fsmEventName)
HutongGames.PlayMaker.Actions.BroadcastEvent.BroadcastToAll () (at Assets/PlayMaker/Actions/BroadcastEvent.cs:60)
HutongGames.PlayMaker.Actions.BroadcastEvent.OnEnter () (at Assets/PlayMaker/Actions/BroadcastEvent.cs:38)
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState)
HutongGames.PlayMaker.Fsm.DoTransition (HutongGames.PlayMaker.FsmTransition transition, Boolean isGlobal)
HutongGames.PlayMaker.Fsm.ChangeState (System.String eventName)
HutongGames.PlayMaker.Fsm.Event (HutongGames.PlayMaker.FsmEvent fsmEvent)
HutongGames.PlayMaker.Actions.FloatCompare.DoCompare () (at Assets/PlayMaker/Actions/FloatCompare.cs:66)
HutongGames.PlayMaker.Actions.FloatCompare.OnUpdate () (at Assets/PlayMaker/Actions/FloatCompare.cs:46)
HutongGames.PlayMaker.FsmState.OnUpdate ()
HutongGames.PlayMaker.Fsm.UpdateState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.Update ()
PlayMakerFSM.Update ()

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Null Reference Exception only when Editor Window is open.
« Reply #3 on: May 25, 2011, 02:27:06 PM »
You guys are talking about two things which I've learned to deeply despise: 1) mixing actions with standard scripts and 2) prefabs. Not especifically in this order :) Working with prototypes (pre-instantiated, disabled objects) is SO much smoother and flexible in every single circumstance compared to raw prefabs that it instantly render the second obsolete. BTW, the prototype object might be linked to a prefab, so that you get the best of both worlds - without never having to "break" a prefab connection or to build awkward "find" scripts just to properly hook the property links during instance, which just degrades the instantiation performance even more than normal.

PS.: Thinking about it, this post was 100% off-topic. It sounds like a "don't fix it, stop using it". My bad, I should stop venting out my completely and shockingly unfashionable ideas in forums lol :)
--
Breno "MaDDoX" Azevedo
@brenoazevedo

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Null Reference Exception only when Editor Window is open.
« Reply #4 on: May 25, 2011, 04:41:34 PM »
@danien - Can you send me your project and repro steps? I'll sign an NDA if needed...

@MaDDoX - Have to admit I was dubious about prototype objects replacing prefabs, but now that you mention the prototype can use a prefab it does seem like the best of both worlds! Will have to give that a try... Reminds me of the workflow in TorqueX (one of the better Torque products!) where you kept prototype objects in the scene but offscreen so you could see all the objects and actors laid out and easily pickable in a "scatchpad" area that you could organize yourself - much more visual than a project hierarchy. The problem then was sharing these prototypes between scenes (don't think they ever came up with a good solution for that).

hima

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Null Reference Exception only when Editor Window is open.
« Reply #5 on: June 02, 2011, 07:29:08 AM »
I have this problem as well but closing the window doesn't help.

This happens to me when I add a new state or remove an existing state from the FSM inside a prefab. Modify the actions are ok, but once I modify a state, then it gives me this error.

What interesting is that, it gives me this error only when I execute Application.LoadLevel to load a level that has an instance of that prefab. If I start from that scene right away, then it won't give me an error.


EDITED : Ok, I fixed the problem now. Here's how to fix it. If you make changes to an FSM that belongs to a prefab, you need to "play each scene that contain an instance of that prefab individually at least once and save it". This will allow the prefab instance to update its FSM to be like its prefab. Or else your prefab instance FSM will still be like the old one and this can give you an error.
« Last Edit: June 02, 2011, 08:06:53 AM by hima »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Null Reference Exception only when Editor Window is open.
« Reply #6 on: June 02, 2011, 09:18:52 AM »
Hi,

 Thanks for the tip!

danien

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 4
Re: Null Reference Exception only when Editor Window is open.
« Reply #7 on: June 18, 2011, 06:11:32 AM »
@danien - Can you send me your project and repro steps? I'll sign an NDA if needed...

Sorry for the late reply - I switched to working on another project.

I can't get it to happen again now but if I remember how, I'll get back to you here. Thanks.

danien

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 4
Re: Null Reference Exception only when Editor Window is open.
« Reply #8 on: June 18, 2011, 08:08:16 AM »
Good news. I created a very simple scene that makes this repeatable.
[MODERATOR EDIT: Download link removed.]

If the Playmaker window is open, running the scene will trigger the NullReferenceException message in the Console. If the Playmaker window is closed, no error is shown in the Console.

The scene is set up as follows:
1. GameObject has a Playmaker state machine that instantiates an instance of TestPrefab, then sends a Broadcast event.
2. TestPrefab also has a Playmaker state machine, with a state waiting on a global transition for the event from GameObject. Once it receives this event, there is a IntCompare action, which seems to be triggering the exception.
« Last Edit: July 05, 2011, 12:50:40 PM by alexchouls »

danien

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 4
Re: Null Reference Exception only when Editor Window is open.
« Reply #9 on: July 04, 2011, 01:13:22 PM »
@alexchouls Were you able to replicate the bug with the test scene?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Null Reference Exception only when Editor Window is open.
« Reply #10 on: July 04, 2011, 04:26:32 PM »
Yes - thanks for the repro project.

The problem seems to be fixed in 1.2. I'll send you the latest beta to test.

Thanks!

scritch

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 11
Re: Null Reference Exception only when Editor Window is open.
« Reply #11 on: September 02, 2011, 02:37:45 PM »
I have a weird permutation of this bug.

In editor I get this:

NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.Continue ()
HutongGames.PlayMaker.Fsm.Update ()
PlayMakerFSM.Update ()

and this:


NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.FsmState.OnLateUpdate ()
HutongGames.PlayMaker.Fsm.LateUpdateState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.LateUpdate ()
PlayMakerFSM.LateUpdate ()


but only if the playmaker window is NOT open.
As soon as I open the playmaker window, and open the FSM in the scene in the playmaker editor, it starts to work.
wha??

is this related to the same problem or no?
when is 1.2 due to be out?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Null Reference Exception only when Editor Window is open.
« Reply #12 on: September 02, 2011, 02:45:15 PM »
Could be related... Wrapping up 1.2 now, should be out any day, but would like to see if it fixes your bug. Can I send it to the email listed in your forum profile?

scritch

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 11
Re: Null Reference Exception only when Editor Window is open.
« Reply #13 on: September 02, 2011, 03:23:31 PM »
yes, sure.
Is 1.2 a drop-in replacement, or does it require any tinkering with anything?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Null Reference Exception only when Editor Window is open.
« Reply #14 on: September 02, 2011, 05:06:32 PM »
Should be drop-in, but you should back up your project!! A few actions are now obsolete and you'll get errors telling you to replace them, but you can turn those off or ignore them until you're ready to swap them out...