Search Unity

Bug After switching to 2021.3.1f1, mono_gc_alloc_string crashes constantly

Discussion in 'Scripting' started by Zergling103, May 17, 2022.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    It has been pretty difficult to get work done lately as some fault in mono keeps rearing its ugly head and causing the world to end abruptly. (Occurs about once every 2-5 minutes.)

    It usually happens when switching levels, but it seems to happen randomly. It'd be easier to figure out these kinds of issues, but they stem from some sort of internal background thread. (Perhaps the console?)

    In any case, it'd take time I don't have to try and isolate this bug in a simple demo project. I guess my naive hope is that a Unity dev might gloss over this thread and double check what this code is doing. Of if a Unity user has encountered this problem before, they'll shed some light on what is going on or how to avoid this problem.

    Any help appreciated, thanks!

    Code (CSharp):
    1. =================================================================
    2.     Managed Stacktrace:
    3. =================================================================
    4.       at <unknown> <0xffffffff>
    5.       at System.String:FastAllocateString <0x000c1>
    6.       at System.String:JoinCore <0x006aa>
    7.       at System.String:Join <0x0014a>
    8.       at System.IO.Path:CanonicalizePath <0x00a7a>
    9.       at System.IO.Path:InsecureGetFullPath <0x00f42>
    10.       at System.IO.Path:GetFullPath <0x00072>
    11.       at System.IO.File:GetLastWriteTime <0x00082>
    12.       at System.IO.DefaultWatcher:IterateAndModifyFilesData <0x0175a>
    13.       at System.IO.DefaultWatcher:DoFiles <0x006ba>
    14.       at System.IO.DefaultWatcher:UpdateDataAndDispatch <0x002ca>
    15.       at System.IO.DefaultWatcher:Monitor <0x006c2>
    16.       at System.Threading.ThreadHelper:ThreadStart_Context <0x00131>
    17.       at System.Threading.ExecutionContext:RunInternal <0x0061d>
    18.       at System.Threading.ExecutionContext:Run <0x0008a>
    19.       at System.Threading.ExecutionContext:Run <0x001e2>
    20.       at System.Threading.ThreadHelper:ThreadStart <0x000aa>
    21.       at System.Object:runtime_invoke_void__this__ <0x00337>
    22. =================================================================
    Code (CSharp):
    1. 0x00007FFF00E08DC2 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\external\bdwgc\malloc.c:333] GC_malloc_kind
    2. 0x00007FFF00B9772D (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\boehm-gc.c:1040] mono_gc_alloc_string
    3. 0x00007FFF00B08500 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:6950] mono_string_new_size_handle
    4. 0x00007FFF00A72F1E (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\icall-def.h:980] ves_icall_System_String_FastAllocateString_raw
    5. 0x0000026F610D6232 (Mono JIT Code) (wrapper managed-to-native) string:FastAllocateString (int)
    6. 0x0000026F61137B2B (Mono JIT Code) string:JoinCore (char*,int,string[],int,int)
    7. 0x0000026F611373DB (Mono JIT Code) string:Join (string,string[],int,int)
    8. 0x0000026F61130A7B (Mono JIT Code) System.IO.Path:CanonicalizePath (string)
    9. 0x0000026F6112D0D3 (Mono JIT Code) System.IO.Path:InsecureGetFullPath (string)
    10. 0x0000026F6112C113 (Mono JIT Code) System.IO.Path:GetFullPath (string)
    11. 0x0000026F6A7EEE53 (Mono JIT Code) System.IO.File:GetLastWriteTime (string)
    12. 0x0000026F6A7BBD6B (Mono JIT Code) System.IO.DefaultWatcher:IterateAndModifyFilesData (System.IO.DefaultWatcherData,string,bool,string[])
    13. 0x0000026F656F3D1B (Mono JIT Code) System.IO.DefaultWatcher:DoFiles (System.IO.DefaultWatcherData,string,bool)
    14. 0x0000026F656F358B (Mono JIT Code) System.IO.DefaultWatcher:UpdateDataAndDispatch (System.IO.DefaultWatcherData,bool)
    15. 0x0000026F656F06C3 (Mono JIT Code) System.IO.DefaultWatcher:Monitor ()
    16. 0x0000026F6239D4C2 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart_Context (object)
    17. 0x0000026F6239C72E (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    18. 0x0000026F6239BD8B (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    19. 0x0000026F6239BBB3 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object)
    20. 0x0000026F6239B69B (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart ()
    21. 0x0000026F6239B408 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    22. 0x00007FFF00BBE0A4 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke
    23. 0x00007FFF00AFE744 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3066] do_runtime_invoke
    24. 0x00007FFF00B0217C (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:4458] mono_runtime_delegate_try_invoke
    25. 0x00007FFF00B2B981 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threads.c:1292] start_wrapper_internal
    26. 0x00007FFF00B2BB26 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threads.c:1344] start_wrapper
    27. 0x00007FFF75C07034 (KERNEL32) BaseThreadInitThunk
    28. 0x00007FFF77042651 (ntdll) RtlUserThreadStart
     
    Last edited: May 17, 2022
  2. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I uploaded the dump file here. If you need to open it, you'll have to change the extension to a .dmp
     

    Attached Files:

  3. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Update: I set the "Stack Trace" settings under Project Settings > Player from "Full" to "None" for all options, and the crashing has stopped. (It has been good for almost an hour now.) I think this certainly narrows down one of the causes to something in the console logging mechanism.
     
  4. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Update: Crashing still occurs fairly regularly from this issue (same cause, same thread). With logging disabled, it is a lot less frequent (things still log to the console), but it occurs about once an hour (sometimes 30 mins, sometimes 2+ hours).
     
  5. Alex-Thibodeau

    Alex-Thibodeau

    Unity Technologies

    Joined:
    Apr 18, 2013
    Posts:
    27
    Have you submitted a bug for this? We can get a better idea as to what's going on if we can reproduce locally.
     
    Zergling103 likes this.
  6. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    No, I haven't - I know that for bugs to actually get through the pipeline to developers, the testers need to reproduce the bug. However:
    • My confidence is low that I'll be able to get this bug happening without zipping up the entire project including the library, as this bug doesn't happen on my co-worker's computer (who has almost identical project files). Sending project files would be an NDA concern.
    • The bug doesn't seem to be triggered by something I am doing, as it occurs in a thread that doesn't execute code in the project or external DLLs I include. So I'm pretty much at a complete loss as to what the repro project would need.
    • I'd have to start deleting as many things as possible while still having the bug occur, which would probably be a week long project. Even though the odds of this working seem pretty low, I'd be willing to spend the time to do this (I know fixing bugs without repro steps is like throwing crap at the walls and hoping something sticks, while blindfolded) if I weren't currently in crunch time.
    However, while a repro project is out of scope for now, I could still submit a bug report if you think it'll nevertheless be useful. I suppose if there are specific files, settings, package changes etc. of interest to a dev who knows more about this system, I could send them.

    Thanks for replying, by the way. :)
     
  7. Alex-Thibodeau

    Alex-Thibodeau

    Unity Technologies

    Joined:
    Apr 18, 2013
    Posts:
    27
    Yeah unfortunately that's kind of the nature of memory corruption bugs. They're slippery and hard to reproduce and even if you can it takes a long time to determine the root cause. I possibly have good news though. There was a fix to a memory corruption bug here: https://issuetracker.unity3d.com/is...hen-closing-it-in-batch-mode-or-when-building that isn't in the version of Unity that you are using. It's 'possible' that the fix is on the way. I took a look at your dump file and it definitely has the odor of memory corruption as it's crashing when attempting to allocate managed memory for a string.
     
    Zergling103 likes this.
  8. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Fair enough. I guess it probably makes more sense that something else is setting up a "trap" that the string allocator trips on.
    We have another DLL - steam audio for Unity - that is very prone to crashing, so perhaps it is partially to blame?
    I wrote some unsafe code - it uses a call to memcpy to quickly copy memory from collision contact data provided by OnCollision to an array that will be passed to a burst job. To be sure, I shut it off to see if it'd stop crashes; no luck.

    It's like trying to solve a murder mystery, and everyone is a suspect.
     
    Last edited: May 20, 2022