Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Destroy(gameObject) Causes intermittent crash of Unity3D

Discussion in 'Editor & General Support' started by NemoKrad, Aug 17, 2016.

  1. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Hi all,

    I am using Unity 5.4.0f3 and when I destroy and object in my scene, some times, not all the time, it causes Unity to crash. This happens with Unity either locking up and I have to kill it with Task Manager, or it locks up, and I then get the Unity "report" window.

    I am not new to Unity and have regularly written this sort of code before. I guess my objects are more complex than normal (they have child game objects and a 3D canvas), but still I would expect Unity to manage the Destroy as it always has and not crash :/

    Can anyone give me any tips on what I could be doing wrong, I have even created a method to try and get around this by having my method destroy all the child objects, as making the object inactive, this seemed to help a little, but the issue just became less frequent.

    I have also found that putting the destroy in a co routine also alters the frequency of the crash.

    Any hints and tips are more than welcome :)

    My destroy looks like this:-
    Code (CSharp):
    1.     void DestroyMe()
    2.     {
    3.         gameObject.SetActive(false);
    4.  
    5.         int children = transform.childCount;
    6.  
    7.         for (int c = children - 1; c >= 0; c--)
    8.             Destroy(transform.GetChild(c).gameObject);
    9.  
    10.         Destroy(gameObject);
    11.     }
     
  2. Dave-Carlile

    Dave-Carlile

    Joined:
    Sep 16, 2012
    Posts:
    967
    NemoKrad likes this.
  3. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    @Dave-Carlile, there is a load in there, anything in particular that should stand out, I can see the name of my scene in there, but not spotted anything saying why it's crashed...

    Here is the content:-
    Anything in there that you can see?

    Thanks for your time by the way :)
     
  4. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Just ran it again, and stopped it so it does not crash, and the logs look pretty much the same, so don't think there is anything in there indicating what could be going wrong :(
     
  5. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    @Dave-Carlile !!

    Just got it to crash and this time it gave the Unity Report Error dialog and now the Editor.log file looks like it is populated with crash info, but still I am none the wiser, anyone here know what's going wrong from this log file message:-

     
  6. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    I have put the error.log and dump file here if this is any use, looking at the error.log now
     
  7. PlutoSylvain

    PlutoSylvain

    Joined:
    Aug 18, 2016
    Posts:
    1
    Getting a crash in Unity 5.4 around GameObject.Destroy as well
     
    NemoKrad likes this.
  8. scott-plutovr

    scott-plutovr

    Joined:
    Aug 27, 2015
    Posts:
    3
    I looked at the crash dumps in windbg and they don't appear to be crashing in the same place although the last frame didn't resolve on the NemoKrad dmp but likely because I don't have the Unity iOS dll that has that function.

    @NemoKrad stack trace:
    upload_2016-8-18_13-22-50.png

    FAILURE_FUNCTION_NAME: CanvasBatchIntermediateRenderer::CleanupSubBatchProperties

    @PlutoSylvain stack trace:
    upload_2016-8-18_13-28-7.png
    FAILURE_FUNCTION_NAME: CContext::TID3D11DeviceContext_Unmap__1_
     
    NemoKrad likes this.
  9. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    Thanks for taking a look Scott :D

    So, in my case, it looks like having the canvas on there is causing or at least part of the issue. Alas, this does not get me any closer to know how to fix this, if indeed I can :/

    The hierarchy of my objects are something like this:-

    GameObject - This is just a transform with a script
    |
    |-->Canvas
    | |-->3D Quad (as the canvas does not write to the depth buffer and I need it to))
    | |-->Image
    | |-->Text
    | |-->Text
    | L-->Button
    L-->GameObject - This is the 3D geom that is rendered for the object.

    My destroy calls are on the top most GameObject, the one that is just a transform.

    This really is quite frustrating :/
     
  10. scott-plutovr

    scott-plutovr

    Joined:
    Aug 27, 2015
    Posts:
    3
    Our top level game object (instantiated from a prefab) has two children. The first a game object named Image and the second a game object named Text. The first has a Rect Transform, a Canvas Renderer and an UI.Image script. The second has a Rect Transform, a Canvas Renderer and a UI.Text script. If both of these children of the top level game object that is being passed to GameObject.Destroy are disabled Unity won't crash. However, if either is enabled Unity crashes on the GameObject.Destroy(). We have also copied this prefab into an empty scene and have been unable to duplicate our crash so we are looking into other things in our scene that could be causing trouble.
     
  11. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    My top level object is also based on a prefab. With my Canvas active or not, this crash is occurring, but my 3D geom is active, so I guess I could try ensuring EVERY child is not active prior to destruction call.

    I am guessing this is an issue with Unity then as a few of us seem to be getting it. Was really hoping 5.4 would be the "stable" release :/
     
  12. breakspirit

    breakspirit

    Joined:
    Aug 11, 2013
    Posts:
    30
    I'm seeing this same problem. When the enemies in my game die and destroy themselves, my game crashes. It only happens when certain other objects in the scene are active. Those objects are always ones that contain cameras in their hierarchy. No idea what the deal is with that.
     
  13. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    I have still not tested the possible fix of having all the children disabled prior to the destroy call, Ill let you know if it works.
     
  14. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    I'm seeing the same issue. I'm using Unity 5.4.0f3 and any time I Destroy and object containing a Canvas, Unity crashes. I've ran into this issue a couple different times. I tested and it's not just happening in a script. If I instantiate a prefab containing a Canvas, unity crashes even when I delete the object from the editor! Sure hope they fix this issue soon!
     
    NemoKrad likes this.
  15. NemoKrad

    NemoKrad

    Joined:
    Jan 16, 2014
    Posts:
    632
    As posted by someone else above, I have found if before I do the destroy, I deactivate the canvas and all it's child elements, it no longer crashes. Well, it is working for me at the moment...
     
  16. diamond2004

    diamond2004

    Joined:
    Jan 24, 2014
    Posts:
    8
    I have the same problem too with Unity 5.4.0f3 on Android. Basically when I am deleting a gameobject that has Canvas component (or one of it's childrend has Canvas component) the game crashes. it doesn't crash right a way though. the stacktrace is as follow:
    Code (CSharp):
    1. 09-14 11:57:23.711  3079  3079 F DEBUG  : backtrace:
    2. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #00 pc 00171a50  /data/app/.../lib/arm/libunity.so (_ZN31CanvasBatchIntermediateRenderer25CleanupSubBatchPropertiesEv+184)
    3. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #01 pc 00171898  /data/app/.../lib/arm/libunity.so (_ZN31CanvasBatchIntermediateRendererD1Ev+36)
    4. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #02 pc 00171ae8  /data/app/.../lib/arm/libunity.so (_ZN31CanvasBatchIntermediateRendererD0Ev+8)
    5. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #03 pc 001587a4  /data/app/.../lib/arm/libunity.so (_ZN21IntermediateRenderers5ClearEj+64)
    6. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #04 pc 001b28a8  /data/app/.../lib/arm/libunity.so (_ZN13RenderManager13RenderCamerasEi+456)
    7. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #05 pc 004eb558  /data/app/.../lib/arm/libunity.so (_Z12PlayerRenderb+352)
    8. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #06 pc 004ec924  /data/app/.../lib/arm/libunity.so (_Z10PlayerLoopbbP10IHookEvent+3992)
    9. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #07 pc 006a1f58  /data/app/.../lib/arm/libunity.so (_Z15UnityPlayerLoopv+1992)
    10. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #08 pc 006a4e5c  /data/app/.../lib/arm/libunity.so (_Z12nativeRenderP7_JNIEnvP8_jobject+264)
    11. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #09 pc 0162ee71  /data/app/.../oat/arm/base.odex (offset 0xa47000) (boolean com.unity3d.player.UnityPlayer.nativeRender()+76)
    12. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #10 pc 0162c011  /data/app/.../oat/arm/base.odex (offset 0xa47000) (boolean com.unity3d.player.UnityPlayer.a(com.unity3d.player.UnityPlayer)+60)
    13. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #11 pc 01628f07  /data/app/.../oat/arm/base.odex (offset 0xa47000) (boolean com.unity3d.player.UnityPlayer$b$1.handleMessage(android.os.Message)+1210)
    14. 09-14 11:57:23.711  3079  3079 F DEBUG  :  #12 pc 03766c3f  /system/framework/arm/boot.oat (offset 0x2f47000)
     
  17. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    NemoKrad likes this.