void OnDestroy() { m_UISystem.UISystemDestroying -= OnDestroy; m_UISystem.SystemReady -= OnSystemReady; foreach (var o in m_ObjectsToDestroy) { UnityEngine.Object.Destroy(o); } m_ObjectsToDestroy.Clear(); m_UISystem.RemoveView(this); if (View != null) { // The ViewRenderer must be destroyed immediately to avoid // an assertion in Unity3D. // It would be more correct to do that in the render thread // using ViewRendererComponent.DestroyViewRenderer(), but // Unity quits too fast and the destruction never happens, // leading to an assert. CoherentUIGTRenderEvents.SendRenderEvent(CoherentRenderEventType.DestroyViewRenderer, View.GetId()); if (ViewRenderer != null) { ViewRenderer.Dispose(); ViewRenderer = null; } View.Destroy(); View.Dispose(); View = null; ViewTexture = null; DepthTexture = null; } if (m_Listener != null) { m_Listener.Dispose(); m_Listener = null; } if (OnViewDestroyed != null) { OnViewDestroyed(); } if (m_AudioClip != null) { DestroyStream(0); } }