1. 程式人生 > >[Unity] UGUI新增刪除子canvas 造成unity閃退 crash 崩潰問題分析。

[Unity] UGUI新增刪除子canvas 造成unity閃退 crash 崩潰問題分析。


專案裡,為了做引導, 把 需要高亮按鈕控制元件  加上 Canvas  GraphicRaycaster 元件,然後設定大的層級。  

結束時再移除這些元件。

沒想到頻繁 造成崩潰。



========== OUTPUTING STACK TRACE ==================


0x00000001407B9B96 (Unity) GameObject::IsActive
0x0000000140FB04D0 (Unity) UI::CanvasRenderer::DirtySyncTypeFlag
0x0000000140FB14B7 (Unity) UI::CanvasRenderer::OnTransformChanged
0x00000001407B88C3 (Unity) MessageHandler::HandleMessage
0x00000001407B8D14 (Unity) GameObject::SendMessageAny
0x0000000140A98A34 (Unity) std::_Uninit_move<unsigned short * __ptr64,unsigned short * __ptr64,stl_allocator<unsigned short,1,16>,unsigned short>
0x0000000140AA50D9 (Unity) Transform::SendTransformChangedToModifiedTransforms
0x0000000140716E45 (Unity) UnityEngine::Animation::SetTransformPropertyApplyMainThread
0x00000001406946E0 (Unity) Animator::WriteProperties
0x00000001406E1E74 (Unity) Animator::UpdateAvatars
0x00000001411EC196 (Unity) DirectorManager::ExecuteStage
0x00000001411EC36E (Unity) DirectorManager::ExecuteStage
0x0000000140BCCA93 (Unity) PlayerLoop
0x0000000141495492 (Unity) Application::UpdateScene
0x0000000141496A5F (Unity) Application::UpdateSceneIfNeeded
0x000000014149F494 (Unity) Application::TickTimer
0x00000001415632AE (Unity) FindMonoBinaryToUse
0x00000001415648D1 (Unity) WinMain
0x000000014187FA98 (Unity) strnlen
0x0000000076D159CD (kernel32) BaseThreadInitThunk
0x0000000076F4A561 (ntdll) RtlUserThreadStart


========== END OF STACKTRACE ===========



========== OUTPUTING STACK TRACE ==================


0x0000000140FB0FC0 (Unity) UI::CanvasRenderer::CanvasHierarchyChanged
0x00000001407B88C3 (Unity) MessageHandler::HandleMessage
0x00000001407B8D14 (Unity) GameObject::SendMessageAny
0x0000000140A973F2 (Unity) Transform::BroadcastMessageAny
0x00000001416BA18D (Unity) UI::Canvas::AddToManager
0x00000001416C0238 (Unity) UI::Canvas::AwakeFromLoad
0x0000000140E5EAFA (Unity) AwakeFromLoadQueue::InvokeAwakeFromLoad
0x0000000140E609FD (Unity) AwakeFromLoadQueue::AwakeFromLoad
0x00000001407BBA0D (Unity) GameObject::ActivateAwakeRecursively
0x00000001407BBD86 (Unity) GameObject::Activate
0x000000002915405D (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:SetActive (bool)
0x000000005A48B3B2 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\Code\ResourceManager\ResourceManager.cs:56] ResourceManager:LoadGameObject (string,System.Action`2<UnityEngine.GameObject, object>,object) 
0x000000005A48AFBC (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\UI\LuaHelper.cs:24] LuaHelper:LoadGameObject (string,LuaInterface.LuaFunction) 
0x000000005A48AB5A (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\LuaHelperWrap.cs:106] LuaHelperWrap:LoadGameObject (intptr) 
0x00000000538780C3 (Mono JIT Code) (wrapper native-to-managed) LuaHelperWrap:LoadGameObject (intptr)
0x0000000066934965 (ulua) lj_BC_FUNCC
0x0000000066940DD3 (ulua) lua_pcall
0x00000000365FD03F (Mono JIT Code) (wrapper managed-to-native) LuaInterface.LuaDLL:lua_pcall (intptr,int,int,int)
0x0000000053B6EE98 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:144] LuaInterface.LuaFunction:PCall (int,int) 
0x000000001FDA3D25 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\ClickEventTriggerWrap.cs:364] ClickEventTriggerWrap/<set_onClick>c__AnonStorey0:<>m__0 (UnityEngine.EventSystems.PointerEventData) 
0x000000001FDA347A (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\Code\ExtraCode\UGUI\ClickEventTrigger.cs:43] ClickEventTrigger:OnPointerClick (UnityEngine.EventSystems.PointerEventData) 
0x000000001FDA2BDF (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:52] UnityEngine.EventSystems.ExecuteEvents:Execute (UnityEngine.EventSystems.IPointerClickHandler,UnityEngine.EventSystems.BaseEventData) 
0x000000001FD9E740 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:269] UnityEngine.EventSystems.ExecuteEvents:Execute<object> (UnityEngine.GameObject,UnityEngine.EventSystems.BaseEventData,UnityEngine.EventSystems.ExecuteEvents/EventFunction`1<object>) 
0x00000000585F1406 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:533] UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress (UnityEngine.EventSystems.PointerInputModule/MouseButtonEventData) 
0x00000000585E6208 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:432] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent (int) 
0x00000000585E5EB9 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:412] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent () 
0x00000000585E3DB2 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:186] UnityEngine.EventSystems.StandaloneInputModule:Process () 
0x0000000053B60101 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:287] UnityEngine.EventSystems.EventSystem:Update () 
0x0000000023D66D52 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x000007FED3F654D7 (mono) [c:\buildslave\mono\build\mono\mini\mini.c:4937] mono_jit_runtime_invoke 
0x000007FED3EB83ED (mono) [c:\buildslave\mono\build\mono\metadata\object.c:2623] mono_runtime_invoke 
0x000000014121413F (Unity) scripting_method_invoke
0x0000000140E425A5 (Unity) ScriptingInvocation::Invoke
0x000000014121635E (Unity) MonoBehaviour::CallMethodIfAvailable
0x0000000141219E92 (Unity) MonoBehaviour::CallUpdateMethod
0x00000001409569CA (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x0000000140956FBF (Unity) BehaviourManager::Update
0x0000000140BCCA3F (Unity) PlayerLoop
0x0000000141495492 (Unity) Application::UpdateScene
0x0000000141496A5F (Unity) Application::UpdateSceneIfNeeded
0x000000014149F494 (Unity) Application::TickTimer
0x00000001415632AE (Unity) FindMonoBinaryToUse
0x00000001415648D1 (Unity) WinMain
0x000000014187FA98 (Unity) strnlen
0x0000000076D159CD (kernel32) BaseThreadInitThunk
0x0000000076F4A561 (ntdll) RtlUserThreadStart


========== END OF STACKTRACE ===========




========== OUTPUTING STACK TRACE ==================


0x00000001416BD6B3 (Unity) UI::Canvas::GetRenderMode
0x0000000140FB1461 (Unity) UI::CanvasRenderer::OnTransformChanged
0x00000001407B88C3 (Unity) MessageHandler::HandleMessage
0x00000001407B8D14 (Unity) GameObject::SendMessageAny
0x0000000140A98A34 (Unity) std::_Uninit_move<unsigned short * __ptr64,unsigned short * __ptr64,stl_allocator<unsigned short,1,16>,unsigned short>
0x0000000140AA5013 (Unity) Transform::SendTransformChanged
0x0000000140A3C7A0 (Unity) UI::RectTransform::UpdatePosAndRectRecursive
0x0000000140A45C0E (Unity) UI::RectTransform::OnTransformChanged
0x00000001407B88C3 (Unity) MessageHandler::HandleMessage
0x00000001407B8D14 (Unity) GameObject::SendMessageAny
0x0000000140A98A34 (Unity) std::_Uninit_move<unsigned short * __ptr64,unsigned short * __ptr64,stl_allocator<unsigned short,1,16>,unsigned short>
0x0000000140A98ADB (Unity) Transform::SendTransformParentingMessages
0x0000000140AA6899 (Unity) Transform::SetParent
0x00000000761414EC (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Transform:SetParent (UnityEngine.Transform,bool)
0x000000003C4351EF (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\TransformWrap.cs:866] TransformWrap:SetParent (intptr) 
0x0000000061C9B4A3 (Mono JIT Code) (wrapper native-to-managed) TransformWrap:SetParent (intptr)
0x0000000066934965 (ulua) lj_BC_FUNCC
0x0000000066940DD3 (ulua) lua_pcall
0x0000000030A57F0F (Mono JIT Code) (wrapper managed-to-native) LuaInterface.LuaDLL:lua_pcall (intptr,int,int,int)
0x000000006610B659 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:70] LuaInterface.LuaFunction:call (object[],System.Type[]) 
0x000000006610B14A (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:91] LuaInterface.LuaFunction:Call (object[]) 
0x000000003C423342 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:113] LuaInterface.LuaFunction:Call (object) 
0x000000003C4343DD (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\UI\LuaHelper.cs:27] LuaHelper/<LoadGameObject>c__AnonStorey2:<>m__0 (UnityEngine.GameObject,object) 
0x000000003C41ECCC (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\Code\ResourceManager\ResourceManager.cs:60] ResourceManager:LoadGameObject (string,System.Action`2<UnityEngine.GameObject, object>,object) 
0x000000003C41E84C (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\UI\LuaHelper.cs:24] LuaHelper:LoadGameObject (string,LuaInterface.LuaFunction) 
0x000000003C41E3EA (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\LuaHelperWrap.cs:106] LuaHelperWrap:LoadGameObject (intptr) 
0x00000000616D1803 (Mono JIT Code) (wrapper native-to-managed) LuaHelperWrap:LoadGameObject (intptr)
0x0000000066934965 (ulua) lj_BC_FUNCC
0x0000000066940DD3 (ulua) lua_pcall
0x0000000030A57F0F (Mono JIT Code) (wrapper managed-to-native) LuaInterface.LuaDLL:lua_pcall (intptr,int,int,int)
0x000000006610B659 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:70] LuaInterface.LuaFunction:call (object[],System.Type[]) 
0x000000006610B14A (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:91] LuaInterface.LuaFunction:Call (object[]) 
0x000000003C423342 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:113] LuaInterface.LuaFunction:Call (object) 
0x000000003C4343DD (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\UI\LuaHelper.cs:27] LuaHelper/<LoadGameObject>c__AnonStorey2:<>m__0 (UnityEngine.GameObject,object) 
0x000000003C41ECCC (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\Code\ResourceManager\ResourceManager.cs:60] ResourceManager:LoadGameObject (string,System.Action`2<UnityEngine.GameObject, object>,object) 
0x000000003C41E84C (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\UI\LuaHelper.cs:24] LuaHelper:LoadGameObject (string,LuaInterface.LuaFunction) 
0x000000003C41E3EA (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\LuaHelperWrap.cs:106] LuaHelperWrap:LoadGameObject (intptr) 
0x00000000616D1803 (Mono JIT Code) (wrapper native-to-managed) LuaHelperWrap:LoadGameObject (intptr)
0x0000000066934965 (ulua) lj_BC_FUNCC
0x0000000066940DD3 (ulua) lua_pcall
0x0000000030A57F0F (Mono JIT Code) (wrapper managed-to-native) LuaInterface.LuaDLL:lua_pcall (intptr,int,int,int)
0x00000000761040F8 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Core\LuaFunction.cs:144] LuaInterface.LuaFunction:PCall (int,int) 
0x000000003C4BE835 (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\CodePublic\uLua\Source\LuaWrap\ClickEventTriggerWrap.cs:364] ClickEventTriggerWrap/<set_onClick>c__AnonStorey0:<>m__0 (UnityEngine.EventSystems.PointerEventData) 
0x000000003C4BE04A (Mono JIT Code) [C:\work\mmo3d_client\mmo3d\Assets\Code\ExtraCode\UGUI\ClickEventTrigger.cs:43] ClickEventTrigger:OnPointerClick (UnityEngine.EventSystems.PointerEventData) 
0x000000003C4BD87F (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:52] UnityEngine.EventSystems.ExecuteEvents:Execute (UnityEngine.EventSystems.IPointerClickHandler,UnityEngine.EventSystems.BaseEventData) 
0x000000003C4B75C0 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:269] UnityEngine.EventSystems.ExecuteEvents:Execute<object> (UnityEngine.GameObject,UnityEngine.EventSystems.BaseEventData,UnityEngine.EventSystems.ExecuteEvents/EventFunction`1<object>) 
0x000000007612B426 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:533] UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress (UnityEngine.EventSystems.PointerInputModule/MouseButtonEventData) 
0x000000007611EFF8 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:432] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent (int) 
0x000000007611ECA9 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:412] UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent () 
0x000000007611CBA2 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:186] UnityEngine.EventSystems.StandaloneInputModule:Process () 
0x00000000661352F1 (Mono JIT Code) [C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:287] UnityEngine.EventSystems.EventSystem:Update () 
0x000000000B066F82 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x000007FED5B454D7 (mono) [c:\buildslave\mono\build\mono\mini\mini.c:4937] mono_jit_runtime_invoke 
0x000007FED5A983ED (mono) [c:\buildslave\mono\build\mono\metadata\object.c:2623] mono_runtime_invoke 
0x000000014121413F (Unity) scripting_method_invoke
0x0000000140E425A5 (Unity) ScriptingInvocation::Invoke
0x000000014121635E (Unity) MonoBehaviour::CallMethodIfAvailable
0x0000000141219E92 (Unity) MonoBehaviour::CallUpdateMethod
0x00000001409569CA (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x0000000140956FBF (Unity) BehaviourManager::Update
0x0000000140BCCA3F (Unity) PlayerLoop
0x0000000141495492 (Unity) Application::UpdateScene
0x0000000141496A5F (Unity) Application::UpdateSceneIfNeeded
0x000000014149F494 (Unity) Application::TickTimer
0x00000001415632AE (Unity) FindMonoBinaryToUse
0x00000001415648D1 (Unity) WinMain
0x000000014187FA98 (Unity) strnlen
0x0000000076D159CD (kernel32) BaseThreadInitThunk
0x0000000076F4A561 (ntdll) RtlUserThreadStart


========== END OF STACKTRACE ===========




最後網上找到一個參考 類似錯誤的:

http://blog.csdn.net/gz_huangzl/article/details/52484907

懷疑是Destroy後,Unity存在一個BUG導致CanvasRenderer還繼續訪問了該物體(已經為NULL)

然後做了延時Destory就好了。


然後這邊就想到了一個思路。   在LateUpdate裡把 Canvas  GraphicRaycaster 元件 移除, 就是等渲染結束再移除canvas元件,, 就不崩潰了。


(最近遇到一個新的閃退情況, 原因應該是一樣的:

  就是 子節點 含有canvas的,移除父節點上的canvas unity就會閃退崩潰(編輯器手動操作都可復現,unity 5.5.x)。
目前方案,先把子節點的canvas先禁用掉,然後再移除父節點的,再恢復子節點的canvas)