Search Unity

IL2CPP: Anyone else seeing MetadataCache::Initialize crashes sometimes when the game starts?

Discussion in 'Android' started by Prodigga, Jan 31, 2016.

  1. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Sometimes, at startup, we get a crash before the game even gets to the splash screen. It seems like something is going wrong with initialising the game. The call stack looks like this:

    Code (CSharp):
    1. at libil2cpp.il2cpp::vm::MetadataCache::Initialize()(vm:40)
    2. at libil2cpp.il2cpp::vm::Runtime::Init(char const*, char const*)(vm:60)
    Just wanted to put it out there and see if anyone else is getting a similar problem on Android? I googled it but all the threads I found were iOS issues from a while ago. Seems iOS was/is experiancing the same issue.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Prodigga

    There was a time when we has some issues on iOS with this code, but I think we've worked out any problems. The fast that this happens sometimes is troubling though. Is there any other diagnostic information available here? This code is doing a good bit of allocation of structures the libil2cpp runtime needs. I wonder if we're running into some type of allocation problem.
     
  3. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Not much else is available. I haven't been able to reliablely reproduce it myself but I *have* seen this one in action myself. It just gives an ANR error as soon as you tap the icon. It generally happens after reinstalling the app (say, after I've made a change that I want to test on the device) and it never seems to happen twice in a row. Sort of like whatever cache it was trying to load up gets wiped when it crashes and on the next run everything is fine because it reinitialised the cache from scratch? I don't know the backend so I am just speculating ofcourse.

    My speculation has led me to believe that maybe these crashes are just from users who receive an update to our game and experience this crash once upon the first launch after that update has been installed. These crashes makes up anther 1/3 of our total reports.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Prodigga

    This code does load the global-metadata.dat file, which is a binary blob that il2cpp.exe generates at build time with all of the .Net metadata that libil2cpp will need at runtime. I wonder if there is some intermittent file access problem which could occur in the cases you described.
     
  5. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Your guess is as good as mine. I'll tey and trigger the problem again tomorrow and see if I can figure out anything else from the crash logs. Maybe there are other errors being throw before the crash dump, so I'll check for things like access violations and anything else that might look a little funny. Will also try and figure out how to reliablely reproduce it. Here's hoping I can reproduce it in a simple project!
     
  6. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    @JoshPeterson submitted a repo today, bug report number 767281

    Seems someone from Unity has already seen it and successful reproduced it on your end.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Prodigga

    Yes, that is correct. It looks like the bug has been fixed internally, and it making its way to release branches. It should land in a 5.3 patch release soon. The actual bug that was corrected is number 766698 (yours was marked as a duplicate of this one). So you should be able to look for that bug number in the release notes.
     
    Prodigga likes this.
  8. sobin

    sobin

    Joined:
    Nov 16, 2015
    Posts:
    1
    @JoshPeterson I reproduced this bug with Unity 5.3.4f1 & 5.3.5f1..
    doesn't these two revisions contain your solution?
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @sobin

    Yes, this issue should be corrected in those versions. Can you provide the full call stack for the crash? Maybe this is a slightly different issue.
     
  10. Yao2ich

    Yao2ich

    Joined:
    May 31, 2016
    Posts:
    3
    Hi,

    I got the similar problem. My situation is that i create an ios project including unity folder as a component. Additionally, i want to setup this component in another project. However it crashes

    @JoshPeterson

    QQ20160531-0@2x.png QQ20160531-1@2x.png
    QQ20160531-2@2x.png .
     

    Attached Files:

    Last edited: May 31, 2016
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Yao2ich

    The Unity code here is looking for a file name 'global-metadata.dat' in a Data/Managed/Metadata directory - that is what MatadataCacge::Initialize loads. If your project is re-packaging the Unity code in a different way, I wonder if that file is missing. Is that the case?
     
  12. Yao2ich

    Yao2ich

    Joined:
    May 31, 2016
    Posts:
    3
    I put the 'global-metadata.dat' in the right way. However, it crashes after point of '
    vm::MetadataLoader::LoadMetadataFile'. Maybe the variable of
    's_Il2CppMetadataRegistration' is null.

    QQ20160531-4@2x.png
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Yao2ich

    If s_Il2CppMetadataRegistration is null, then something did not load properly related to metadata. Can you provide this project in a bug report? It seems like a case we've not seen yet, so I would like to investigate it here.
     
    haxpor likes this.
  14. Yao2ich

    Yao2ich

    Joined:
    May 31, 2016
    Posts:
    3
    ok, thx
     
  15. lenyan

    lenyan

    Joined:
    Aug 8, 2016
    Posts:
    1
    @Yao2ich
    I got the similar problem with you,did you solve this problem?
     
  16. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    I'm trying to achieve the same thing as @Yao2ich. I changed [NSBundle mainBundle] to [NSBundle bundleForClass:] to refer to the right bundle of framework. Tested it to confirm, and finally I experienced a crash as seen in the following screenshot.
     

    Attached Files:

  17. nguyentrongvan

    nguyentrongvan

    Joined:
    Sep 10, 2016
    Posts:
    1
    Useful. Thanks
     
  18. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    @josh
    Josh, I think at the end my problem is the same as @Yao2ich . I checked global-metadata.dat file was there, and the code passes, and then stuck at similar place as him, but I cannot see the code only assembly code here .

    Did this problem submitted as bug report already? I want to know its status. Right now I'm trying 5.4.1, but not sure it would solve the problem.
     
  19. cj657206427

    cj657206427

    Joined:
    Oct 20, 2016
    Posts:
    4
    @haxpor
    I also met the same problem,what's your solution?
     
  20. firetrap

    firetrap

    Joined:
    Jan 2, 2017
    Posts:
    2
    Last edited: Jan 2, 2017
  21. firetrap

    firetrap

    Joined:
    Jan 2, 2017
    Posts:
    2
    Anyone with the same problem! Find "UnityAppController.mm" in "didFinishLaunchingWithOptions:" replace "
    UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);
    by:
    NSBundle * bundle = [NSBundlebundleForClass:[self class]];
    UnityInitApplicationNoGraphics([[bundle bundlePath] UTF8String]);
     
    Last edited: Jan 3, 2017
  22. Ed_bt

    Ed_bt

    Joined:
    Oct 1, 2012
    Posts:
    19
    Hey everybody! Can any kind soul give any hints on how to create a framework or pod of an exported unity project? When creating pod the mac runs always out of resources...memory and disk. Those 20k files on Native folder are not helping. This task is really important for distribution and maintainability. Thanks folks!
     
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Ed_bt

    I'm not entirely sure what you mean by "a framework or pod of an exported unity project", but the twenty thousand source files in the Native directory are probably the ones generated by il2cpp.exe. They are the converted IL code from the managed assemblies that will be used by the C++ compiler to create the native executable.

    We did not intend to have them shipped anywhere outside of a build machine though. Once you have an executable, they are not required to run the Unity player.

    Note that in Unity 5.6 we'll likely have fewer generated files, but there still will be a good bit of content there.
     
  24. Ed_bt

    Ed_bt

    Joined:
    Oct 1, 2012
    Posts:
    19
    Tanks for the input Josh! What I meant was I bundled the unity ios exported project into a cocoa touch Framework having in mind distribution and maintainability. I then added the created Framework (roughly 120mb) to the native project but I keep hitting "Undefined symbols not found for architecture armv7 _UnityInitRuntime referenced from _main in main.o. Might have something to do with fact that the function is included in the following category

    referenced in trampoline and implemented in unity player lib" as stated on UnityInterface.h.

    With that function commented (yeah I know I wont go far) the whole project successfully builds although the engine launch crashes with the error mentioned in the first post.

    Would like to hear more from you guys and If I can help in anything do ask!

    Cheers
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Ed_bt

    I don't think that I can help too much more, as I'm not too familiar with issue like this on iOS. I don't think that repackaging Unity projects like this is something we support, but others with iOS-specific knowledge might be able to help.
     
  26. Ed_bt

    Ed_bt

    Joined:
    Oct 1, 2012
    Posts:
    19
    Thank for you assistance nevertheless Josh! Myself and co worker hit a wall with this both with pod creation and framework. MetadataLoader.cpp line 13...although the file is present (global-metadata.dat) and referenced on the project il2cpp cannot find it and thus generating the error. Josh can you point us to someone who can help us understand if what we are trying to accomplish is even possible or if the nature of how il2cpp works is binded to that rigid path of the dat file. On the exported project I moved the dat file and found the exact same error. It's like it can only see if its in Data/Managed/Metadata. God dammit! Is it protection on your side? Once again thank you very much :)
     
    Last edited: Jan 10, 2017
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Ed_bt

    Right now the global-metadata.dat file must be located in the Data/Managed/Metadata directory. That path is hard-coded in the executable. This isn't really for protection of any sort, it is just convenience for us. We don't need to expose an option to locate it in a different directory, so it is simpler to hard-code it.

    I would suspect that what you are trying to accomplish is not possible, at least without access to the Unity source code so that you can modify it. Although maybe others on the forums have had success with something like this. Unfortunately I don't know of anyone to recommend though.

    If you do find something that works, please be aware that we may change the location of the global-metadata.dat file without notice, as it is not part of the public API. I don't expect that to happen soon, but it is something to keep in mind.
     
  28. dingxiuweiUnity

    dingxiuweiUnity

    Joined:
    Dec 27, 2016
    Posts:
    5
    I also met the same problem。 i had put the global-metadata.dat in right way。@JoshPeterson , would you help me?thanks。
    10.jpeg 11.jpeg
     
  29. dingxiuweiUnity

    dingxiuweiUnity

    Joined:
    Dec 27, 2016
    Posts:
    5
    @JoshPeterson
    I also met the same problem。 i had put the global-metadata.dat in right way。But run crash still。 Then I found if change framework‘s Mach-O Type to Dynamic Library 。This problem will be solved!
    But why? one is static library dependency ,one is dynamic library, the other is source code dependency!

    Unity 5.5.1f1 xcode 8.2.1
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @dingxiuweiUnity

    I don't know why this works as a dynamic library, sorry. I would need to understand more about the specific situation. But I'm glad you were able to get this to work.
     
  31. dingxiuweiUnity

    dingxiuweiUnity

    Joined:
    Dec 27, 2016
    Posts:
    5
    @JoshPeterson ,Thank you.

    I need to search for a new solution。 Because my app must supports ios7 and later,but dynamic library only support ios8 and later.

    Notice Me, If somebody solves this problem!
     
  32. xiaoyi6409

    xiaoyi6409

    Joined:
    Mar 22, 2017
    Posts:
    1
    I met the same problem too, but if I import the Data to my iOS project by "creat folder references" and import the Classes&Libraries by " creat groups", the problem will be solved
     

    Attached Files:

    jake-ruman likes this.
  33. UnknownRE

    UnknownRE

    Joined:
    Apr 18, 2017
    Posts:
    6
    I met the same problem, and I found that MetadataCache crashes because the MetadataCache::Register function (which is supposed to be called before MetadataCache is initalized), is actually never called.

    This happens when you try to initialize the Unity runtime from outside the main binary: you can solve the problem by manually calling "s_Il2CppCodegenRegistration()" before "UnityInitApplicationNoGraphics(...)".

    The problem is that, in my case, this only works if I try to init Unity from a static library: when I try from a dynamic one, I get a crash on "il2cpp::metadata::Il2CppGenericClassCompare".

    Any help, please? @JoshPeterson
     
    forest_linshs likes this.
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @UnknownRE

    I'm not sure what is happening. We don't support this kind of initialization of Unity outside of it's normal path. If you would like to submit a bug report with your project we might be able to have a look at it, but I cannot promise a fix for an issue like this.
     
  35. jake-ruman

    jake-ruman

    Joined:
    Oct 21, 2016
    Posts:
    5
    Yeah, it can be solved using your way!! Thank you. But I meet another crash.


    @JoshPeterson @xiaoyi6409 do you have any idea?
     
  36. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6

    Attached Files:

  37. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6
    Do you have a solution?
     
  38. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6
    #0 il2cpp::vm::MetadataCache::Initialize()
    #1 il2cpp::vm::Runtime::Init(char const*, char const*)
    #2 ::InitializeIl2CppFromMain()
    #3 ::UnityInitApplicationNoGraphics()
    #4 ::-[UnityAppController application:didFinishLaunchingWithOptions:](UIApplication *, NSDictionary *)
    #5 ::-[AppDelegate application:didFinishLaunchingWithOptions:](UIApplication *, NSDictionary *)
    报:Thread 1:EXC_BAD_ACCESS(code=1,address=0×.......)
     
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    @Alai_

    Does this happen with a normal Unity project, or is this a case where the Unity code is hosted in some other iOS application?
     
  40. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6
    in iOS application
     
  41. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6
    I guess it's about the Data folder path
     
  42. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    Unfortunately, I can't offer too much help. This is not something we support, and I don't understand how things all hang together in the final iOS app.
     
  43. Alai_

    Alai_

    Joined:
    Aug 8, 2017
    Posts:
    6
    Thank you all the same
     
  44. Deleted User

    Deleted User

    Guest

    The same is happening with me.

    I'm trying to integrate a Unity scene with my iOS project and the crash happens all the time.
     

    Attached Files:

  45. caiovm

    caiovm

    Joined:
    Aug 9, 2012
    Posts:
    4
    Hello guys! We have a special approach to build our Unity iOS project and we recently faced the same issue after updating it from Unity 5.6.2p2 to Unity 2017.1.0p2.

    Based on what @UnknownRE suggested we checked that if we include -DRUNTIME_IL2CPP=1 in Other C Flags the following code would be enabled in Il2CppCodeRegistration.cpp file:
    Code (CSharp):
    1. #if RUNTIME_IL2CPP
    2.  
    3. static il2cpp::utils::RegisterRuntimeInitializeAndCleanup s_Il2CppCodegenRegistrationVariable (&s_Il2CppCodegenRegistration, NULL);
    4.  
    5. #endif
    Everything is working fine after adding the flag.
     
  46. akalisingh

    akalisingh

    Joined:
    May 4, 2014
    Posts:
    1
    @caiovm did you compile a static library that was imported into another project and it worked?

    @UnknownRE how did you manually call "s_Il2CppCodegenRegistration()" method? Did you include a header file?
     
  47. dgoodineyv

    dgoodineyv

    Joined:
    Apr 15, 2017
    Posts:
    1
    @caiovm Thanks, your solution worked. It appears that define is new. It wasn't in Unity 5.6.0. Kinda boneheaded to need the define at all, since iOS only supports the IL2CPP runtime.
     
  48. Cripple

    Cripple

    Joined:
    Aug 16, 2012
    Posts:
    92
    Got his on UWP too, any idea on how to fix it pls ?

    Cheers
     
  49. mehdisarkeshi

    mehdisarkeshi

    Joined:
    Oct 5, 2017
    Posts:
    1
    @caiovm! You are a lifesaver! Worked like a charm!
     
  50. 357545146

    357545146

    Joined:
    Nov 1, 2017
    Posts:
    2
    I have the same issue when create static framework, but ok when create dynamic framework.