Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ryan on November 01, 2012, 08:16:25 PM

Title: UICamera bug with bundled UIs
Post by: ryan on November 01, 2012, 08:16:25 PM
We're using asset bundles with some of our UI, and we discovered that apparently OnDestroy doesn't get called on objects destroyed as a result of a bundle being unloaded.  (At least this is what one of our other engineers tells me.)  That means if you unload a bundle that contained a UICamera, the static list of cameras isn't being properly cleaned up.  Patch below (against a slightly out of date version of NGUI) :

  1. Index: UICamera.cs
  2. ===================================================================
  3. --- UICamera.cs (revision 9034)
  4. +++ UICamera.cs (working copy)
  5. @@ -371,6 +371,8 @@
  6.  
  7.         static int CompareFunc (UICamera a, UICamera b)
  8.         {
  9. +               if (a == null) return b == null ? 0 : 1;
  10. +               if (b == null) return -1;
  11.                 if (a.cachedCamera.depth < b.cachedCamera.depth) return 1;
  12.                 if (a.cachedCamera.depth > b.cachedCamera.depth) return -1;
  13.                 return 0;
  14. @@ -387,7 +389,7 @@
  15.                         UICamera cam = mList[i];
  16.                        
  17.                         // Skip inactive scripts
  18. -                       if (!cam.enabled || !cam.gameObject.active) continue;
  19. +                       if (cam == null || !cam.enabled || !cam.gameObject.active) continue;
  20.  
  21.                         // Convert to view space
  22.                         currentCamera = cam.cachedCamera;
  23. @@ -418,6 +420,7 @@
  24.                 for (int i = 0; i < mList.Count; ++i)
  25.                 {
  26.                         UICamera cam = mList[i];
  27. +                       if (cam == null) continue;
  28.                         Camera uc = cam.cachedCamera;
  29.                         if ((uc != null) && (uc.cullingMask & layerMask) != 0) return cam;
  30.                 }
  31.  

Title: Re: UICamera bug with bundled UIs
Post by: ArenMook on November 02, 2012, 02:44:34 AM
Sounds like a bug that should be reported to Unity.