Search Unity

Mono Crash: OP_LOADV_MEMBASE, codebase emitting invalid IL in editor only, how to debug?

Discussion in 'Scripting' started by nijnstein, Apr 30, 2022.

  1. nijnstein

    nijnstein

    Joined:
    Feb 6, 2021
    Posts:
    78
    After importing a codebase into unity (4mb of cs code) i get mono crashes in editor builds. Release builds with il2cpp work fine.

    It crashes with the assertion:
    Code (CSharp):
    1. Assertion at C:\build\output\Unity-Technologies\mono\mono\mini\method-to-ir.c:12983, condition `load_opcode != OP_LOADV_MEMBASE' not met
    The log message is always at some random time after starting the project, the only errormessage to find is the above assertion. The analysis of the exception in the dump aint really helpfull either:
    Code (csharp):
    1.  
    2. STACK_TEXT:
    3. 00000027`14d6dd80 00007ffb`0cd9064c     : 000001ba`531842c0 00007ffb`0d436398 00007ffb`0d37bdeb 00007ffb`0d37bdeb : KERNELBASE!RaiseException+0x69
    4. 00000027`14d6de60 00007ffb`0cd7c4a2     : 00007ffb`0d37bd88 000001ba`55763160 00000000`00000000 00000027`14d6e3d8 : mono_2_0_bdwgc!mono_dl_fallback_unregister+0xf8c
    5. 00000027`14d6df20 00007ffb`0cd7c57c     : 00000000`00061f08 00000000`00002000 000001ba`04159068 00000000`00000000 : mono_2_0_bdwgc!BrotliEncoderVersion+0xe1e2
    6. 00000027`14d6e3a0 00007ffb`0cd7c5c9     : 00007ffb`0d37bd88 00007ffb`0d3abee0 00000000`000032b7 00007ffb`0d3adb28 : mono_2_0_bdwgc!BrotliEncoderVersion+0xe2bc
    7. 00000027`14d6e3d0 00007ffb`0d01d624     : 00000000`00061f08 000001ba`531841d0 00000000`00000400 00000000`00000000 : mono_2_0_bdwgc!BrotliEncoderVersion+0xe309
    8. 00000027`14d6e400 00007ffb`0cf947e9     : 000007bb`3578b53a 00000000`00000008 000001b8`e5598570 00000027`14d6e830 : mono_2_0_bdwgc!mono_set_break_policy+0x78cd4
    9. 00000027`14d6e730 00007ffb`0cf95317     : 000007bb`351bf0e3 00000027`14d6ef20 00000000`00000000 00000027`14d6ef20 : mono_2_0_bdwgc!mono_unity_class_has_failure+0xa729
    10. 00000027`14d6ecf0 00007ffb`0cf9bfcc     : 000001ba`20578fe0 000001b8`b4d22a80 00000000`00000000 00000000`00000000 : mono_2_0_bdwgc!mono_unity_class_has_failure+0xb257
    11. 00000027`14d6ed60 00007ffb`0d08ee8f     : 00000000`00000000 00000027`14d6ee89 000001ba`20578fe0 000001b7`06baf370 : mono_2_0_bdwgc!mono_jit_set_domain+0x375c
    12. 00000027`14d6edd0 00007ffb`0d08fa58     : 000001ba`20578fe0 000001b9`dcfc4f2b 00000000`49706267 00000000`00000000 : mono_2_0_bdwgc!mono_install_ftnptr_eh_callback+0x1d3f
    13. 00000027`14d6eee0 000001b8`b4b803a6     : 00000027`14d6f2a0 000001b9`c19502b8 000001b9`c19400b6 00007ffb`c489b3c7 : mono_2_0_bdwgc!mono_install_ftnptr_eh_callback+0x2908
    14. 00000027`14d6f090 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : 0x000001b8`b4b803a6
    15.  
    16.  
    17. STACK_COMMAND:  ~0s; .ecxr ; kb
    18.  
    19. SYMBOL_NAME:  mono_2_0_bdwgc+f8c
    20.  
    21. MODULE_NAME: mono_2_0_bdwgc
    22.  
    23. IMAGE_NAME:  mono-2.0-bdwgc.dll
    24.  
    25. FAILURE_BUCKET_ID:  APPLICATION_FAULT_e0000001_mono-2.0-bdwgc.dll!Unknown
    26.  
    27. OS_VERSION:  10.0.19041.1
    28.  
    After some searching OP_LOADV_MEMBASE the only references i found were old bugs in mono, related to aliasing of local variables. If im not mistaking that is the following construct:

    Code (csharp):
    1.  
    2. switch(var)
    3. {
    4.   case a:
    5.   {
    6.       float f1 = 11f; return math.sin(i);
    7.   }
    8.   case b:
    9.   {
    10.       float f2 = 22f; return math.sin(j);   // f1 and f2 use the same local variable after compilation
    11.   }
    12. }
    13.  
    I do have a lot of code like this, is the only option for me then to uncomment/comment many sections of code to find out which part causes this? Can i somehow find out on what piece of code the aot compiler crashes?

    Unity editor version: 2021.3.0f1
     
  2. nijnstein

    nijnstein

    Joined:
    Feb 6, 2021
    Posts:
    78
    somehow i found it.. it reduced to the use of


    v4 = quaternion.Euler( -((float3*)fdata)[0], rotation_order).value;


    Commenting / removing this line made the error go away.

    It is used in an inlined function. v4 is of type V4 an alias for a float4:

    using V4 = Unity.Mathematics.float4;


    Making the aggressive inlining of the function calling this conditional like so:

    #if ENABLE_IL2CPP
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    #endif


    Makes the problem dissapear, this only seems to be a problem in code using quaternions in mono builds and i have no idea why im the only one that has this problem as there are very few google hits on OP_LOADV_MEMBASE.
     
    Last edited: May 1, 2022
  3. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    161
    Hi @nijnstein
    I'm encountering the same error when compiling. The only symptom difference seems to be that my crash occurs before the editor has the chance to open. It crashes when compiling (while the splash/logo screen is displayed).

    Unity 2022.2.6. Using Burst and Entities packages.

    Can you describe how you went about pin pointing the problematic line of code? I'm a bit at a loss for what to do next.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    Did you also try blowing away the Library/ folder within your project, or perhaps just the Library/IL2CPPBuildCache folder?
     
  5. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    161
    I'll try that when the crash report finishes uploading. Thanks for the suggestion.
     
  6. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    161
    No luck, same crash.
     
    Kurt-Dekker likes this.
  7. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    161
    For anyone having the same issue: I submitted a bug report and it's under review. In the meantime, here's the only "work around" I found (disclaimer: it's painful):

    The goal here is to find which piece of code is making the compilation crash.
    1. Make sure your project is under version control
    2. Delete all your project code
    3. Restore your code files using the versioning software. Instead of doing 1 by 1, start by assemblies with the fewest dependencies (start at the bottom). Every time you restore code from an assembly, make sure Unity compiles it correctly. If Unity has compilation errors, it won't help you. If Unity crashes, you found the assembly with problematic code. After that, you have to redelete those files, and restart the code restoration process, but file-by-file instead.

    It's terrible, but after a few hours, you should find the problematic code file and method. After that, you can try to work around the crash by rewriting the code in a different syntax, or report a bug to Unity.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    Now I'm curious! Can you post a snippet that made IL2CPP choke and how you refactored it?

    (Just for chin-scratching sakes, no real purpose other than for me to go "Huh!")
     
  9. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    161
    I was not compiling in IL2CPP. And I did not look at the produced IL. Sorry.

    I'm not 100% sure, but I believe some of the generated code from the Entities package was incorrect and it was causing this compilation crash.
     
    Kurt-Dekker likes this.