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.

Same problem :frowning:
Version: 2017.3.0p4

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)

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.

It seems that upgrading to Unity 2017.4.1f1 finally solves this issue.

Back in 2021.3.10f1 LTS. Really frustrating to set up the UI in the Editor.

Unity 2021.3.10f1 LTS have the problem

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

0x00007ff76c01facf (Unity) UI::CanvasRenderer::Deactivate
0x00007ff76b397f57 (Unity) GameObject::ActivateAwakeRecursivelyInternal
0x00007ff76b397b69 (Unity) GameObject::ActivateAwakeRecursively
0x00007ff76b39a829 (Unity) GameObject::Deactivate
0x00007ff76b6ab8a5 (Unity) DestroyObjectHighLevel_Internal
0x00007ff76b6ab4f4 (Unity) DestroyObjectHighLevel
0x00007ff76c93b71b (Unity) CreatedObjectUndo::ApplyUndo
0x00007ff76c93b83b (Unity) UndoManager::ApplyUndo
0x00007ff76c9450c7 (Unity) UndoManager::Undo
0x00007ff76c4464c0 (Unity) MenuController::ExecuteMenuItem
0x00007ff76c445ba2 (Unity) MenuController::ExecuteMainMenuItem
0x00007ff76b05da9e (Unity) EditorApplication_CUSTOM_ExecuteMenuItem
0x00000177874caa6a (Mono JIT Code) (wrapper managed-to-native) UnityEditor.EditorApplication:ExecuteMenuItem (string)