Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Editor Crash on PrefabUtility.SaveAsPrefabAsset

Discussion in 'Editor & General Support' started by pw_aowen, Feb 10, 2021.

  1. pw_aowen

    pw_aowen

    Joined:
    Nov 30, 2018
    Posts:
    12
    Hi all,

    Issue on Unity 2018.4.28f1

    My development team keeps running into crashes during their workflow. It doesn't happen consistently, so we don't have solid repro steps.

    They're editing some prefabs out of a custom EditorWindow we've made. The window keeps track of a GameObject (the prefab they're editing) and when they're done, they hit a custom "Save" button. Save will do some processing and then call PrefabUtility.SaveAsPrefabAsset. Sometimes, it crashes at this step.

    Here's an excerpt from the error.log

    Code (CSharp):
    1. Unity.exe caused an Access Violation (0xc0000005)
    2.   in module Unity.exe at 0033:409f50d7.
    3.  
    4. Error occurred at 2021-02-09_195244.
    5. C:\Program Files\Unity\Editor\Unity.exe, run by developer.
    6.  
    7. 87% physical memory in use.
    8. 16170 MB physical memory [1958 MB free].
    9. 8360 MB process peak paging file [5543 MB used].
    10. 5034 MB process peak working set [3347 MB used].
    11. System Commit Total/Limit/Peak: 32253MB/38835MB/36527MB
    12. System Physical Total/Available: 16170MB/1958MB
    13. System Process Count: 335
    14. System Thread Count: 4945
    15. System Handle Count: 169977
    16. Disk space data for 'C:\Users\developer\AppData\Local\Temp\Unity\Editor\Crashes\Crash_2021-02-10_005235068\': 689025802240 bytes free of 1004183818240 total.
    17.  
    18. Write to location 00000000000000BC caused an access violation.
    19.  
    20. Context:
    21. RDI:    0x0000000000000000  RSI: 0x0000000000000006  RAX:   0x0000000003fa05f0
    22. RBX:    0x00000000071e91c0  RCX: 0x0000000000000001  RDX:   0x0000000000000000
    23. RIP:    0x00000001409f50d7  RBP: 0x0000000000000000  SegCs: 0x0000000000000033
    24. EFlags: 0x0000000000010246  RSP: 0x00000000005fa7b0  SegSs: 0x000000000000002b
    25. R8:     0x0000000000000006  R9:  0x00000000003ffff8  R10:   0x0000000003fc3090
    26. R11:    0x00000000005fa9a8  R12: 0x00000000a14b7510  R13:   0x0000000000000000
    27. R14:    0x0000000000000000  R15: 0x0000000000000000
    28.  
    29.  
    30. Bytes at CS:EIP:
    31. c7 87 bc 00 00 00 02 00 00 00 e8 ba 05 93 00 48
    32.  
    33. Mono DLL loaded successfully at 'C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll'.
    34.  
    35.  
    36. Stack Trace of Crashed Thread 4404:
    37. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00000001409F50D7)
    38. 0x00000001409F50D7 (Unity) (function-name not available)
    39. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000140FE20F5)
    40. 0x0000000140FE20F5 (Unity) (function-name not available)
    41. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5763E)
    42. 0x0000000141F5763E (Unity) (function-name not available)
    43. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F6973F)
    44. 0x0000000141F6973F (Unity) (function-name not available)
    45. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5D4EE)
    46. 0x0000000141F5D4EE (Unity) (function-name not available)
    47. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F6793B)
    48. 0x0000000141F6793B (Unity) (function-name not available)
    49. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5827B)
    50. 0x0000000141F5827B (Unity) (function-name not available)
    51. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F15407)
    52. 0x0000000141F15407 (Unity) (function-name not available)
    53. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000140E71BA6)
    54. 0x0000000140E71BA6 (Unity) (function-name not available)
    55. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 000000014107E4E3)
    56. 0x000000014107E4E3 (Unity) (function-name not available)
    57. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00000001423DE968)
    58. 0x00000001423DE968 (Unity) (function-name not available)
    59. 0x000000006FB3D1B0 (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset_Internal()
    60. 0x000000006FB3AE3B (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset()
    61. 0x000000006FB3ACAB (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset()
    62. 0x000000006FB1E3FB (LeapingLemur.Editor) LeapingLemurEditorUtils.SavePrefab()
    63. 0x000000006FB1DA53 (LeapingLemur.Editor) LeapingLemurToolInspect.Save()
    Does anyone have any context on what's happening here? I tried to find symbols for the missing function name, but I couldn't find them. I'm guessing the crash is because of something our custom window is doing, but I don't have very many leads...

    I've attached the crash.dmp file.

    Any known pitfalls with SaveAsPrefabAsset? Can someone translate this stack trace?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Nothing that should cause this kaboom!

    I'm going to translate it loosely as "Unity stepped on its shoelaces and fell down."

    That crash looks related to debugging, but it also looks very low-level-y, like somebody went looking at a piece of memory that they weren't supposed to, and you certainly don't have any control of that at the scripting level.

    Perhaps someone else from Unity can chime in? I'd say file a bug but if your project is massive and the steps to repro are undefined, not sure if it would be much help.
     
    pw_aowen likes this.
  3. pw_aowen

    pw_aowen

    Joined:
    Nov 30, 2018
    Posts:
    12
    Thanks for your response! Yeah, there isn't a debugger attached or anything like that. I don't think it's RAM related either, I've seen a error.log that had 8GB free. (I wish it was something that easy)
     
  4. pw_aowen

    pw_aowen

    Joined:
    Nov 30, 2018
    Posts:
    12
    Hello, this is still impacting my team. Here's a new error.log snippet

    Code (CSharp):
    1. Unity Editor by Unity Technologies [version: Unity 2018.4.28f1_a2d4f71491a4]
    2. Unity.exe caused an Access Violation (0xc0000005)
    3.   in module Unity.exe at 0033:409f50d7.
    4. Error occurred at 2021-02-11_170340.
    5. C:\Program Files\Unity\Editor\Unity.exe, run by developer.
    6. 81% physical memory in use.
    7. 16170 MB physical memory [2927 MB free].
    8. 8949 MB process peak paging file [5441 MB used].
    9. 5228 MB process peak working set [3713 MB used].
    10. System Commit Total/Limit/Peak: 32137MB/39899MB/37044MB
    11. System Physical Total/Available: 16170MB/2927MB
    12. System Process Count: 338
    13. System Thread Count: 5087
    14. System Handle Count: 190867
    15. Disk space data for 'C:\Users\developer\AppData\Local\Temp\Unity\Editor\Crashes\Crash_2021-02-11_220330625\': 685893582848 bytes free of 1004183818240 total.
    16. Write to location 00000000000000BC caused an access violation.
    17. Context:
    18. RDI:    0x0000000000000000  RSI: 0x0000000000000006  RAX:   0x0000000052abc770
    19. RBX:    0x00000000072971c0  RCX: 0x0000000000000001  RDX:   0x0000000000000000
    20. RIP:    0x00000001409f50d7  RBP: 0x0000000000000000  SegCs: 0x0000000000000033
    21. EFlags: 0x0000000000010246  RSP: 0x00000000005fa7c0  SegSs: 0x000000000000002b
    22. R8:     0x0000000000000006  R9:  0x00000000003ffff8  R10:   0x0000000004287090
    23. R11:    0x00000000005fa9b8  R12: 0x000000016d4dcd00  R13:   0x0000000000000000
    24. R14:    0x0000000000000000  R15: 0x0000000000000000
    25. Bytes at CS:EIP:
    26. c7 87 bc 00 00 00 02 00 00 00 e8 ba 05 93 00 48
    27. Mono DLL loaded successfully at 'C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll'.
    28. Stack Trace of Crashed Thread 7500:
    29. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00000001409F50D7)
    30. 0x00000001409F50D7 (Unity) (function-name not available)
    31. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000140FE20F5)
    32. 0x0000000140FE20F5 (Unity) (function-name not available)
    33. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5763E)
    34. 0x0000000141F5763E (Unity) (function-name not available)
    35. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F6973F)
    36. 0x0000000141F6973F (Unity) (function-name not available)
    37. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5D4EE)
    38. 0x0000000141F5D4EE (Unity) (function-name not available)
    39. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F6793B)
    40. 0x0000000141F6793B (Unity) (function-name not available)
    41. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F5827B)
    42. 0x0000000141F5827B (Unity) (function-name not available)
    43. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000141F15407)
    44. 0x0000000141F15407 (Unity) (function-name not available)
    45. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 0000000140E71BA6)
    46. 0x0000000140E71BA6 (Unity) (function-name not available)
    47. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 000000014107E4E3)
    48. 0x000000014107E4E3 (Unity) (function-name not available)
    49. ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00000001423DE968)
    50. 0x00000001423DE968 (Unity) (function-name not available)
    51. 0x000000006551EB40 (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset_Internal()
    52. 0x000000006551C42B (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset()
    53. 0x000000006551C29B (UnityEditor) UnityEditor.PrefabUtility.SaveAsPrefabAsset()
    54. 0x0000000065510C6B (LeapingLemur.Editor) LeapingLemurEditorUtils.SavePrefab()
    55. 0x00000000655102D3 (LeapingLemur.Editor) LeapingLemurToolInspect.Save()
    56. 0x00000000654FFB03 (LeapingLemur.Editor) LeapingLemurToolInspect.<ShowMenu>b__52_0()
    57. 0x000000006550FF42 (UnityEditor) UnityEditor.GenericMenu.CatchMenu()
    58. 0x000000006550FB1F (UnityEditor) <Module>.runtime_invoke_void__this___object_object_int()
    59.  
    I've attached the new .dmp as well.

    Could a Unity developer translate the stack trace for me? Or does someone know where the symbol files for the Unity Editor are? Not the symbols for like, the standalone player. My WinDbg couldn't translate them after I pointed it to the symbols endpoint (unless I was using it wrong, : / )
     

    Attached Files:

  5. adsmith

    adsmith

    Joined:
    Jan 14, 2020
    Posts:
    3
    Any update here? Looks like it'll be hard to get much more traction without a Unity developer looking at the crash dump
     
  6. pw_aowen

    pw_aowen

    Joined:
    Nov 30, 2018
    Posts:
    12
    Hi everyone, giving an update here, since I'm still debugging this issue.

    1) I got symbols to work! Using WinDbg and the instructions here: https://docs.unity3d.com/Manual/WindowsDebugging.html
    It was my first time using WinDbg, but I managed to figure it out and parse the stacktrace.

    2) One observation I made was that several threads were stuck on
    ZwWaitForSingleObject or some variant of "waiting". This lead me to suspect a deadlock. My custom Editor window will edit maybe 2 or 3 assets at once. I found AssetDatabase.Start and StopAssetEditing, which the docs recommend when editing several assets at once. https://docs.unity3d.com/2018.4/Documentation/ScriptReference/AssetDatabase.StartAssetEditing.html

    I wrapped our custom Save calls in the try-finally recommended for Start and StopAssetEditing. Unfortunately, this did not resolve the issue. The latest stack trace includes StopAssetEditing, so I'm going to start thinking about that. I attached the .dmp

    Code (CSharp):
    1. [0xc]   ntdll!RtlDispatchException + 0x244  
    2. [0xd]   ntdll!KiUserExceptionDispatch + 0x2e  
    3. [0xe]   Unity!DebugStringToFile + 0x63  
    4. [0xf]   Unity!RuntimeSceneManager::EndIntegrateMainThread + 0xb7  
    5. [0x10]   Unity!PrefabImporter::GenerateAssetData + 0x835  
    6. [0x11]   Unity!AssetDatabaseV1::ImportAsset + 0x52e  
    7. [0x12]   Unity!AssetDatabaseV1::UpdateAsset + 0x138f  
    8. [0x13]   Unity!AssetInterface::ProcessAssetsImplementation + 0x68e  
    9. [0x14]   Unity!AssetInterface::StopAssetEditing + 0x65b  
     

    Attached Files:

  7. pw_aowen

    pw_aowen

    Joined:
    Nov 30, 2018
    Posts:
    12
    Hi all, we figured it out!

    It wasn't mentioned in the crash.dmp or the error.log, but the Editor.log has this log line

    "Attempting to open > 63 preview scenes, this is not supported, ensure you dispose of preview scenes properly"

    Google wasn't especially helpful, but this was a lead. Our custom Editor window was trying to open dozens of preview scenes? Not quite, it turns out it was calling PrefabUtility.LoadPrefabContents, which instantiates a new preview scene, but we were never unloading the prefab with PrefabUtility.UnloadPrefabContents. This meant slowly, but surely, we were leaking preview scenes.

    Part of the tricky bit of tracking this down is that when you have too many preview scenes open, it seems just about any interaction with the Asset Database (or asset import pipeline) will cause Unity Editor to crash. This explains why we would see the crash with stack traces including AssetDatabase.StopAssetEditing and PrefabUtility.SavePrefabAsAsset.

    I simplified the behavior with a toy Unity project. Open up Crash Tools > Crash Window, open up prefabs until it crashes. I'll attach the project.

    I opened up a bug report with Unity, and they reproduced with Unity 2018, but not with Unity 2019. This makes sense, Asset Database V2 probably fixes it, or avoids the problem completely. They recommended an upgrade. Unfortunately, my project timeline doesn't have room for a major Unity upgrade, but that's OK, we shouldn't be leaking scenes either. Link: https://fogbugz.unity3d.com/default.asp?1316452_ee4akrvke2eqmjoj
     

    Attached Files: