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) :
Index: UICamera.cs
===================================================================
--- UICamera.cs (revision 9034)
+++ UICamera.cs (working copy)
@@ -371,6 +371,8 @@
static int CompareFunc (UICamera a, UICamera b)
{
+ if (a == null) return b == null ? 0 : 1;
+ if (b == null) return -1;
if (a.cachedCamera.depth < b.cachedCamera.depth) return 1;
if (a.cachedCamera.depth > b.cachedCamera.depth) return -1;
return 0;
@@ -387,7 +389,7 @@
UICamera cam = mList[i];
// Skip inactive scripts
- if (!cam.enabled || !cam.gameObject.active) continue;
+ if (cam == null || !cam.enabled || !cam.gameObject.active) continue;
// Convert to view space
currentCamera = cam.cachedCamera;
@@ -418,6 +420,7 @@
for (int i = 0; i < mList.Count; ++i)
{
UICamera cam = mList[i];
+ if (cam == null) continue;
Camera uc = cam.cachedCamera;
if ((uc != null) && (uc.cullingMask & layerMask) != 0) return cam;
}