Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ababab5 on October 30, 2014, 10:22:25 AM

Title: NullReferenceException after running
Post by: ababab5 on October 30, 2014, 10:22:25 AM
Hi,

When I created a UIRoot, and I run my game, I have this error when I stop it :

  1. NullReferenceException: Object reference not set to an instance of an object
  2. UIPanel.get_worldCorners () (at Assets/NGUI/Scripts/UI/UIPanel.cs:623)
  3. UIPanelInspector.OnSceneGUI () (at Assets/NGUI/Scripts/Editor/UIPanelInspector.cs:87)
  4. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
  5. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  6. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
  7. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
  8. UnityEditor.SceneView.CallOnSceneGUI ()
  9. UnityEditor.SceneView.HandleSelectionAndOnSceneGUI ()
  10. UnityEditor.SceneView.OnGUI ()
  11. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
  12. UnityEditor.DockArea:OnGUI()
  13.  

Here a video of the issue :

https://www.dropbox.com/s/xkg6f41hbx40hqo/ngui%20error.mov?dl=0 (https://www.dropbox.com/s/xkg6f41hbx40hqo/ngui%20error.mov?dl=0)

What can I do ?

Thanks.
Title: Re: NullReferenceException after running
Post by: ArenMook on October 30, 2014, 01:05:05 PM
That's something in the inspector... nothing in inspector should be trying to get panel's world corners. Not sure what you're doing there. What version of NGUI and Unity? Does it still happen if you restart Unity?
Title: Re: NullReferenceException after running
Post by: ababab5 on October 30, 2014, 01:14:31 PM
Hi,

Unity = 4.6

NGUI = 3.7.5

Yes it happens when I restart unity.


Title: Re: NullReferenceException after running
Post by: ArenMook on October 30, 2014, 01:34:37 PM
Alright, not sure about the last 4.6 beta. I suggest trying it in the latest stable 4.5 release.
Title: Re: NullReferenceException after running
Post by: juggernate on October 30, 2014, 10:45:32 PM
I just updated to 4.5.5p3 and I'm getting this too (not seeing on 4.5.5p2, I re-installed to check).
It seems to run/play fine in editor, but when I stop a bunch of my GUI elements lose their positioning and if I select my UI Root I get this same error.
Seeing this with NGUI 3.7.4 and 3.7.5

I also see the error below a bunch of times if I have items in my UI selected in Editor Hierarchy

  1. The targets array should not be used inside OnSceneGUI or OnPreviewGUI. Use the single target property instead.
  2. UnityEditor.DockArea:OnGUI()

Title: Re: NullReferenceException after running
Post by: ababab5 on October 31, 2014, 04:22:48 AM
I confirm too : I tried like you asked me on Unity 4.5.5.

The same error...
Title: Re: NullReferenceException after running
Post by: ArenMook on November 01, 2014, 05:07:14 AM
I wonder what Unity changed there... well, change line 623 of UIPanel.cs to this:
  1. if (anchorOffset && (mCam == null || mCam.transform.parent != cachedTransform))
Title: Re: NullReferenceException after running
Post by: ababab5 on November 01, 2014, 07:12:10 AM
Hi,

Thanks.

But I already have this :

  1. if (anchorOffset && mCam == null || mCam.transform.parent != cachedTransform)

So .. the same you asked us to add .. :(
Title: Re: NullReferenceException after running
Post by: ArenMook on November 01, 2014, 08:08:45 AM
Not the same. Note the brackets.
Title: Re: NullReferenceException after running
Post by: juggernate on November 01, 2014, 04:36:17 PM
The extra parentheses remove the errors for me. But there are issues with anchoring in editor mode, which means I can no longer edit the anchors visually in Editor with 4.5.5p3. All of the anchored items snap to their target's center, and I no longer see the pink/purple outline of the UIRoot (I'm not sure if that outline is for the root or panel as I'm just using a single panel)

But once I hit play they seem to anchor fine and I see the pink outline again.
Title: Re: NullReferenceException after running
Post by: ArenMook on November 02, 2014, 04:05:52 AM
Sounds like Unity broke something important. I suggest bug reporting it to them.
Title: Re: NullReferenceException after running
Post by: mishaps on November 03, 2014, 04:34:07 AM
yea I've experienced this issue too in unity 4.5.5p3. Downgrading back to unity 4.5.5p1 makes it go away for now.
Title: Re: NullReferenceException after running
Post by: juggernate on November 03, 2014, 10:13:23 AM
Submitted a bug to Unity http://fogbugz.unity3d.com/default.asp?644750_5jopc75lb108290b (http://fogbugz.unity3d.com/default.asp?644750_5jopc75lb108290b)

I've also confirmed this on Windows with Unity 4.5.5p3.
An additional note: If the project rebuilds after a code change, or the target platform changes in the build settings, the anchoring seems to work without playing in the editor. Once play starts and then quits in editor however the anchoring is once again lost.
Title: Re: NullReferenceException after running
Post by: Aernarion on November 03, 2014, 11:48:18 AM
Everything is reproducible on Mac OSX 10.10 with Unity 4.5.5p3 and NGUI 3.7.5. Rebuilding the code seems to solve the issue as well, until play is pressed.

EDIT: I have been playing around and the anchors established after updating Unity to 4.5.5p3 keeps breaking and doing weird things. I need this version since it solves an issue related with Vuforia and iOS and I would not like to have to be switching from p2 to p3 to design and compile.

Did anyone get a workaround to this issue? Aren, could you give us a hand to figure out something while the bug report is managed?

Thank you very much in advance.
Title: Re: NullReferenceException after running
Post by: juggernate on November 04, 2014, 09:24:46 AM
I also just tested this on the latest 4.6 betas:
- 4.6.0b20 anchoring is fine
- 4.6.0b21 anchoring is broken
Title: Re: NullReferenceException after running
Post by: ArenMook on November 04, 2014, 10:45:50 AM
What does NGUITools.screenSize report?

I'm guessing this is where the change lies. Have a look at what's different in terms of returned values inside this function on the two versions of Unity.
Title: Re: NullReferenceException after running
Post by: juggernate on November 04, 2014, 02:35:39 PM
They report the same values in both p2 and p3. But I'm printing NGUITools.screenSize to console at runtime, which is when the anchors look fine. I'm not sure how to debug.log when play is stopped?
Title: Re: NullReferenceException after running
Post by: ArenMook on November 06, 2014, 01:09:09 AM
I just gave the latest Pro version a try on the latest Unity 5 beta, and everything works as expected. All anchors work. To do a debug.log at edit time you can create a function like this:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.     [ContextMenu("Execute")]
  6.     void Execute () { Debug.Log("Hello world!"); }
  7. }
You can then right-click the script in inspector (after attaching it to some object) and choosing "Execute" from the drop-down list.
Title: Re: NullReferenceException after running
Post by: juggernate on November 06, 2014, 02:22:34 PM
Ah, thanks. I tried that and NGUITools.screenSize reports the same values when the anchors look correct during play or when the anchors break while stopped
Title: Re: NullReferenceException after running
Post by: juggernate on November 07, 2014, 08:51:29 PM
Thanks for the workaround/fix in 3.7.6!
Title: Re: NullReferenceException after running
Post by: ArenMook on November 09, 2014, 08:58:27 PM
Unity broke OnValidate in the last few versions, it's no longer affected by the script execution order -- which is why the anchoring issues started happening. I added a work-around for this bug in 3.7.6 so it should work as expected again. In the meantime I also submitted a bug to Unity -- #646217.
Title: Re: NullReferenceException after running
Post by: dannypb on January 09, 2015, 11:32:10 AM
I had the strangest thing happen with this.  I went to change the code line 623 as above and when I saved it in monodevelop, it deleted a number of lines of code.  I undid the changes and tried to save what was there and it did it again.  I tried this a few times to no avail.  Every time monodevelop would delete about 800 or so lines of code. 

I pulled it up in textpad and restored the file from a clipboard copy I made and saved it in it's original format, thinking I would test it first then make the edit on line 623 as above.  When I tested it with the original code the error was gone. 

I wonder if there were some special characters in the script that gave monodevelop and unity problems.  Now that I saved it in an editor that stripped those out, everything works fine.