Unity 4.6.9 - iOS IL2CPP Crashes

I am using Unity version 4.6.9. I am getting crash with “ArgumentNullException: Argument cannot be null”. Everything works fine when building with Mono and for Android. Is this related to prime31? Does anyone came across this issue?

Below is the null exception i am getting in Xcode (version 6.4):

(Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)

ArgumentNullException: Argument cannot be null.
Parameter name: collection
  at System.Collections.Generic.Dictionary`2[System.String,Prime31.Reflection.CacheResolver+MemberMap]..ctor (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] in <filename unknown>:0
  at System.Collections.Generic.List`1[UnityEngine.Camera].CheckCollection (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
  at System.Collections.Generic.List`1[UnityEngine.Camera].AddRange (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
  at OutpostProgressModel.InitTowerPlacements () [0x00000] in <filename unknown>:0
  at UserInfo.GetOutpostProgress (OutpostType outpostType) [0x00000] in <filename unknown>:0
  at UserInfo.GetOutpostProgress (RegionType regionType) [0x00000] in <filename unknown>:0
  at RegionMap.Init (.UISceneState state) [0x00000] in <filename unknown>:0
  at UISceneState+<Load>c__IteratorE5.MoveNext () [0x00000] in <filename unknown>:0
  at RegionMapSceneState+<Load>c__Iterator156.MoveNext () [0x00000] in <filename unknown>:0
  at CoreTask.MoveNext () [0x00000] in <filename unknown>:0

[B](Filename: currently not available on il2cpp Line: 4294967295)[/B]

@JoshPeterson Please can you suggest something?

@kingofasgard

Usually when we see a managed NullReferenceException exception on IL2CPP and not on Mono, it means that something in the IL2CPP stripping process removed some code a bit too aggressively. You can usually verify this by building using the Mono scripting backend with byte code stripping enabled. You may see the same issue.

In order to determine what was incorrectly stripped, you may need to debug the generated C++ code when the exception occurs. You can set an exception breakpoint in Xcode, then look up the native call stack to see what is missing. See this blog post for some details:

Once you determine what is missing, you can use a link.xml file to preserve the things that are getting stripped. You can find more details here:

Note that I’m only guessing about the cause of the problem though. If you debug this and find that my guess here does not make sense, we may need to have a look at the project in a bug report.

1 Like

@JoshPeterson
Hey as you said when using Mono scripting backend with byte code stripping enable, this is issue is coming; this definitely means what you are guessing is right. Some thing is getting stripped when i am compiling with IL2CPP.
I was trying to find what is getting incorrectly stripped in il2cpp but I am unable to understand the generated C++ code, its not readable code for me, Below is the link.xml’s we have int he project and the stack trace output on crash:
What should we do? or do i need to create bug report for this?
we have two link.xml files in the project for preserving.

link.xml (first file)
<linker>
<assemblyfullname="System">
<typefullname="System.ComponentModel.TypeDescriptor"preserve="all"/>
<typefullname="System.ComponentModel.TypeConverter"preserve="all"/>
<typefullname="System.ComponentModel.StringConverter"preserve="all"/>
<typefullname="System.ComponentModel.BooleanConverter"preserve="all"/>
<typefullname="System.ComponentModel.EnumConverter"preserve="all"/>
<typefullname="System.ComponentModel.Int64Converter"preserve="all"/>
<typefullname="System.ComponentModel.Int32Converter"preserve="all"/>
<typefullname="System.ComponentModel.Int16Converter"preserve="all"/>
<typefullname="System.ComponentModel.ArrayConverter"preserve="all"/>
<typefullname="System.ComponentModel.CollectionConverter"preserve="all"/>
<typefullname="System.ComponentModel.DecimalConverter"preserve="all"/>
<typefullname="System.ComponentModel.SingleConverter"preserve="all"/>
<typefullname="System.ComponentModel.DoubleConverter"preserve="all"/>
</assembly>
</linker>

link.xml (second  file)
<linker>
<assemblyfullname="System">
<typefullname="System.ComponentModel.Int32Converter"preserve="all"/>
<typefullname="System.ComponentModel.UInt32Converter"preserve="all"/>
<typefullname="System.ComponentModel.DecimalConverter"preserve="all"/>
<typefullname="System.ComponentModel.SingleConverter"preserve="all"/>
<typefullname="System.ComponentModel.DoubleConverter"preserve="all"/>
</assembly>
<assemblyfullname="mscorlib">
<namespacefullname="System.Security.Cryptography"preserve="all"/>
</assembly>
</linker>

the stack trace output on crash:

Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: collection
  at System.Collections.Generic.Dictionary`2[TKey,TValue]..ctor (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[T].CheckCollection (IEnumerable`1 collection) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[T].AddRange (IEnumerable`1 collection) [0x00000] in <filename unknown>:0 
  at OutpostProgressModel.InitTowerPlacements () [0x00000] in <filename unknown>:0 
  at UserInfo.GetOutpostProgress (OutpostType outpostType) [0x00000] in <filename unknown>:0 
  at UserInfo.GetOutpostProgress (RegionType regionType) [0x00000] in <filename unknown>:0 
  at RegionMap.Init (.UISceneState state) [0x00000] in <filename unknown>:0 
  at UISceneState+<Load>c__IteratorE5.MoveNext () [0x00000] in <filename unknown>:0 
  at RegionMapSceneState+<Load>c__Iterator156.MoveNext () [0x00000] in <filename unknown>:0 
  at CoreTask.MoveNext () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogError(Object)
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)
System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)

(Filename: /Users/builduser/buildslave/unity/build/artifacts/iPhonePlayer-armv7-il2cppGenerated/UnityEngineDebug.cpp Line: 56)

2015-11-12 23:20:38.544 mixels[3606:315798] (
    0   mixels                              0x0000000100090114 _Z29CrashedCheckBellowForHintsWhyv + 44
    1   mixels                              0x000000010154b19c UnhandledExceptionHandler_NativeUnhandledExceptionHandler_m33990 + 76
    2   mixels                              0x000000010154af9c UnhandledExceptionHandler_HandleUnhandledException_m33988 + 260
    3   mixels                              0x00000001018b86e0 UnhandledExceptionEventHandler_Invoke_m49970 + 256
    4   mixels                              0x0000000101c5286c Z43RuntimeInvoker_Void_t5330_Object_t_Object_tPK10MethodInfoPvPS2 + 80
    5   mixels                              0x0000000102479644 _ZN6il2cpp2vm7Runtime30CallUnhandledExceptionDelegateEP12Il2CppDomainP14Il2CppDelegateP12Il2CppObject + 108
    6   mixels                              0x00000001024795c4 _ZN6il2cpp2vm7Runtime18UnhandledExceptionEP12Il2CppObject + 116
    7   mixels                              0x0000000101f73a44 _ZN19ScriptingInvocation28AdjustArgumentsToMatchMethodEv + 0
    8   mixels                              0x0000000101f7387c _ZN19ScriptingInvocation6InvokeIbEET_PP18ScriptingException + 28
    9   mixels                              0x0000000101f69e38 _ZN9Coroutine14InvokeMoveNextEPP18ScriptingException + 88
    10  mixels                              0x0000000101f69b88 _ZN9Coroutine3RunEv + 48
    11  mixels                              0x0000000101e9f944 _ZN18DelayedCallManager6UpdateEi + 568
    12  mixels                              0x0000000101f288fc _Z10PlayerLoopbbP10IHookEvent + 1204
    13  mixels                              0x0000000101d0c364 UnityPlayerLoop + 32
    14  mixels                              0x0000000100083f68 _ZL16UnityRepaintImplb + 108
    15  mixels                              0x0000000100083778 UnityRepaint + 20
    16  mixels                              0x0000000100083758 -[UnityAppController(Rendering) repaint] + 92
    17  mixels                              0x0000000100083648 __51-[UnityAppController(Rendering) repaintDisplayLink]_block_invoke + 76
    18  libdispatch.dylib                   0x00000001055b4fd4 _dispatch_call_block_and_release + 24
    19  libdispatch.dylib                   0x00000001055b4f94 _dispatch_client_callout + 16
    20  libdispatch.dylib                   0x00000001055b9c28 _dispatch_main_queue_callback_4CF + 1864
    21  CoreFoundation                      0x00000001850bf7f8 <redacted> + 12
    22  CoreFoundation                      0x00000001850bd8a0 <redacted> + 1492
    23  CoreFoundation                      0x0000000184fe92d4 CFRunLoopRunSpecific + 396
    24  GraphicsServices                    0x000000018ea3f6fc GSEventRunModal + 168
    25  UIKit                               0x0000000189be6f40 UIApplicationMain + 1488
    26  mixels                              0x000000010007da34 main + 244
    27  libdyld.dylib                       0x000000019747ea08 <redacted> + 4
)

Thanks a lot.

I am facing difficulty in determining which classes are getting stripped in error even though the game requires them; I have tried comparing Xcode projects for stripped byte code of 32 bit and disabled stripping cde of 32 bit.

@kingofasgard

Thanks for the details. I’m now wondering if this is related to stripping of some native engine code instead of managed code. For stripping of native engine code, the link.xml will not have an impact, as it only deals with managed code. Can you attempt to set the “Stripping Level” option in the Player Settings to a value of “Disabled” (if it is not already). That will prevent the native engine code from being stripped, and may correct this issue.

If that still does not work, then it is probably a good idea to submit a bug report, and we can have a look.

@JoshPeterson

  1. 32bit-Mono(2x) build with Stripping Level: Disabled is working fine, and its on store already.
  2. 64bit-IL2CPP (or Universal) build with Stripping Level: Disabled is causing this Crash with (ArgumentNullException)
  3. 32bit-Mono2x build with Stripping Level: Strip Byte Code is causing the same Crash as above.
    Script Call Optimization: Fast but no exceptions.

Thank you for helping us out we are struggling with this issue from last 2 months.

Have you checked your using the latest Prime 31 plugin versions as you said this in your first posting.

@kingofasgard

It does look like this is a bug we should investigate. Can you submit a bug report?

@JoshPeterson Yes, I will submit a bug report and inform you. I have to take permission from management. :expressionless:
@MrEsquire Yes. I have checked we are using latest Prime 31 plugins also we were able to create other IL2CPP projects successfully using same Prim31 updates.

@JoshPeterson Submitted the bug report with project as attachment.
ticket: 746960_kre8qqottkeupqnj
https://fogbugz.unity3d.com/default.asp?746960_kre8qqottkeupqnj

Please look into this. Apologies for the delay for submitting the bug report.

@kingofasgard

Thanks, we will investigate this bug report.

1 Like

@JoshPeterson update: we have just found that this project (32 bit) is working fine only with Unity 4.6.2f1. Game is released on appstore using Unity 4.6.2f1. From 4.6.3 onwards we are getting this issue for 32 bit also.
64 bit is not working with latest IL2CPP unity patches we have tried 4.6.9p1,p2 and p3. Are you guys looking into this issue?

@kingofasgard

Yes, our QA team is investigating this issue now.

1 Like

@JoshPeterson Did you guys found anything?

@kingofasgard

Sorry, it looks like this is still with our QA team. I’ve pinged them again about it.

@JoshPeterson Thanks

@JoshPeterson Any update about this issue?

@kingofasgard

Sorry, nothing yet. Our QA team is looking into it again now though.