Hard crash when enabling/disabling UI elements
It happens a lot in Unity 2017.2 and 2017.3.0p1. I wasted weeks trying to get rid of this random crashes, both in editor and Android builds.
Basically, if you quickly click over UI elements that activate/deactivate others, or when you quit the game, you get an hard crash, both in editor and Android builds, with vague (or zero) information logged.
A typical stack trace shows this (Android):
Thread 0 (crashed)
0 . <unknown>
1 Mono Runtime at (wrapper managed-to-native) UnityEngine.GameObject.SetActive (bool) <IL 0x0002e, 0xffffffff>
2 Mono Runtime at Angrymals.Game.Menu.AuthenticationPanel.ShowLoginForm (Angrymals.Game.Menu.LoginFormType) [0x00057] in H:\Angrymals Development\Game Client\AngrymalsGame\Assets\Angrymals\Scripts\Menu\AuthenticationPanel.cs:69
or this (Editor):
========== OUTPUTING STACK TRACE ==================
0x00000001403BECA6 (Unity) GameObject::IsActive
0x00000001417EB0D5 (Unity) UI::CanvasManager::AddDirtyRenderer
0x00000001417F0D0C (Unity) UI::CanvasRenderer::AwakeFromLoad
0x0000000140A9867A (Unity) AwakeFromLoadQueue::InvokeAwakeFromLoad
0x0000000140A9A391 (Unity) AwakeFromLoadQueue::AwakeFromLoad
0x00000001403C02DF (Unity) GameObject::ActivateAwakeRecursively
0x00000001403C06B6 (Unity) GameObject::Activate
0x0000000035817165 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:SetActive (bool)
0x000000004BC2D157 (Mono JIT Code) [H:\Angrymals Development\Game Client\AngrymalsGame\Assets\Angrymals\Scripts\Battlefield\GUI\Controls\AppearingToggle.cs:38] Angrymals.Game.Menu.AppearingToggle:Toggle ()
This kind of bug has been reported here, one year and half ago.
I also noticed an identical behavior related to activating an object with an Animator component. (another example with GameObject.SetActive and Animator can be found here)
Other reports:
Logs also often point out some Access violation reading location problem.
Anyone else facing this issue? Any idea on how to solve it, or at least to get the Unity team to work on it?
It's basically impossible to ship a game that randomly crashes when user clicks on the UI.
I reverted to 2017.1.3f1 and I'm stuck to that version since then to avoid this bug. This is quite insane.
Answer by Menion-Leah · Apr 13, 2018 at 02:34 PM
It seems that upgrading to Unity 2017.4.1f1 finally solves this issue.
I found it https://unity3d.com/fr/unity/qa/lts-releases
Answer by hadesfury · Mar 30, 2018 at 10:11 AM
Unity 2017.2.2p2 have the problem
========== OUTPUTING STACK TRACE ==================
0x000000014025DDC6 (Unity) GameObject::IsActive
0x00000001417824B5 (Unity) UI::CanvasManager::AddDirtyRenderer
0x00000001417898EC (Unity) UI::CanvasRenderer::AwakeFromLoad
0x00000001409911DA (Unity) AwakeFromLoadQueue::InvokeAwakeFromLoad
0x0000000140992EA1 (Unity) AwakeFromLoadQueue::AwakeFromLoad
0x000000014025F4EF (Unity) GameObject::ActivateAwakeRecursively
0x000000014025F8CB (Unity) GameObject::Activate
0x00000000341285F5 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:SetActive (bool)
Answer by ALL-CAPS · Apr 12, 2018 at 08:06 AM
We had (almost) the same problem in Unity 2017.3.1f1
It turned out our problem was caused by reparenting a UI element from our object pool holder (standard gameObject) into a subcanvas (canvas inside a canvas). When we changed the second Canvas into a CanvasGroup instead, the problem disappeared entirely.