Author Topic: MissingReferenceException when destroying an object containing a UILabel  (Read 6512 times)

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
After upgrading to 3.0.6 rc3 I've been getting this occurrence now whenever an object in the running scene has been destroyed. It points to:

#if UNITY_EDITOR
      UnityEditor.EditorUtility.SetDirty(this);
#endif


Any ideas?

MissingReferenceException: The object of type 'UILabel' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UIWidget.MarkAsChanged () (at Assets/Plugins/NGUI/Internal/UIWidget.cs:596)
UILabel.MarkAsChanged () (at Assets/Plugins/NGUI/UI/UILabel.cs:913)
UnityEngine.Font.InvokeFontTextureRebuildCallback_Internal () (at C:/BuildAgent/work/ea95e74f6e5f192d/Runtime/ExportGenerated/Editor/Graphics.cs:4702)
UnityEngine.Font:RequestCharactersInTexture(String, Int32, FontStyle)
NGUIText:WrapText(Font, String, String&) (at Assets/Plugins/NGUI/Internal/NGUIText.cs:389)
UILabel:ProcessText(Boolean) (at Assets/Plugins/NGUI/UI/UILabel.cs:962)
UILabel:ProcessText() (at Assets/Plugins/NGUI/UI/UILabel.cs:920)
UILabel:ProcessAndRequest() (at Assets/Plugins/NGUI/UI/UILabel.cs:815)
UILabel:OnValidate() (at Assets/Plugins/NGUI/UI/UILabel.cs:874)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: MissingReferenceException when destroying an object containing a UILabel
« Reply #1 on: November 25, 2013, 12:40:41 AM »
You can add
  1. if (this == null) return;
at the top of the MarkAsChanged() function exit out early, but I'd be curious to know how you get to this state. It seems some label gets destroyed, and yet it doesn't remove its notification callback -- and that's something that should be happening in UILabel.OnDisable() as a result of SetActiveFont(null);

pahe

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
    • View Profile
Re: MissingReferenceException when destroying an object containing a UILabel
« Reply #2 on: November 25, 2013, 01:40:58 AM »
I can say that we have a similar problem in 3.0.5. Don't know if it still occurs as we haven't updated yet. We ignored the problem as it seemed only to happen in the editor, but when it destroyed the font as in 2.7 (dynamic font was displayed in broken glyphs).

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: MissingReferenceException when destroying an object containing a UILabel
« Reply #3 on: November 25, 2013, 03:26:12 AM »
I haven't had any luck with understanding why this has suddenly started happening, but as I've dived into it a bit more, it doesn't seem to even be a consistent error, and not necessarily related to a UILabel being destroyed.
For example I have it happening on a simple FPS UILabel I made for debugging- it might occur on 3 of 7 launches. Not sure why, it's almost as if the UILabel isn't ready for when I'm setting UILabel.text = stuff

Just to be perfectly clear, this is the FPS script (a modified version from the Unity wiki)
  1.  var updateInterval = 0.5;
  2.  
  3. private var accum = 0.0; // FPS accumulated over the interval
  4. private var frames = 0; // Frames drawn over the interval
  5. private var timeleft : float; // Left time for current interval
  6. private var textField:UILabel;
  7.  
  8. function Start()
  9. {
  10.     timeleft = updateInterval;  
  11.         textField = gameObject.GetComponent("UILabel") as UILabel;
  12. }
  13.  
  14. function Update()
  15. {
  16.     timeleft -= Time.deltaTime;
  17.     accum += Time.timeScale/Time.deltaTime;
  18.     ++frames;
  19.  
  20.     if( timeleft <= 0.0 )
  21.     {
  22.         // display two fractional digits (f2 format)
  23.         textField.text = "" + (accum/frames).ToString("f2") + "fps\n" + Profiler.GetMonoUsedSize().ToString("N0") + " GetMonoUsedSize of "
  24.         + SystemInfo.systemMemorySize.ToString("N0") + " systemMemorySize" ;
  25.         timeleft = updateInterval;
  26.         accum = 0.0;
  27.         frames = 0;
  28.     }
  29. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: MissingReferenceException when destroying an object containing a UILabel
« Reply #4 on: November 25, 2013, 03:27:17 AM »
As a note, I added that null check into 3.0.6 f1.

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: MissingReferenceException when destroying an object containing a UILabel
« Reply #5 on: November 25, 2013, 03:32:46 AM »
Cool. Adding that does seem to successfully prevent the errors.