• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Frank_O · Dec 05, 2014 at 08:35 PM · iossave databinaryaotjit

Saving Data on IOS produces JIT Error in Xcode

(first of all, I had some trouble with this question editior and marking something as code didn´t seem work :(. Iam sorry if my post is not that easily readable. Thanks for your help and time in advance)

Hello Unity Community,

i have a big problem with saving my data on an IOS device. I started with the Live Session from Mike Geig here on the unity Learn Page and altered the variables a little bit so it fits my needs (Link : PERSISTENCE - SAVING AND LOADING DATA about half way through ). Implementation went smooth and easy and everything works perfectly ... but only in the Unity Editor.

When I install my Game on my test Iphone 5s (up to date IOS and Xcode) and run it I get this Output from Xcode:

2014-12-05 20:23:18.400 BOSS[637:159369] -> registered mono modules 0x14ab620 -> applicationDidFinishLaunching() Mono path[0] = '/private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed' Mono config path = '/private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed' -> applicationDidBecomeActive() Requesting Resolution: 640x1136 Renderer: Apple A7 GPU Vendor: Apple Inc. Version: OpenGL ES 3.0 Apple A7 GPU - 50.6.10 GL_OES_standard_derivatives GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_texture_filter_anisotropic GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_rgb_422 GL_APPLE_texture_format_BGRA8888 GL_IMG_read_format GL_IMG_texture_compression_pvrtc Creating OpenGL ES 3.0 graphics device Initialize engine version: 4.6.0f3 (30840d631a27) Begin MonoManager ReloadAssembly Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/UnityEngine.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/UnityEngine.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/System.dll (this message is harmless) Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Mono.Security.dll (this message is harmless) Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-CSharp-firstpass.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-CSharp-firstpass.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-CSharp.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-CSharp.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/UnityEngine.UI.dll (this message is harmless) Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/System.Core.dll (this message is harmless) Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-UnityScript-firstpass.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-UnityScript-firstpass.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Boo.Lang.dll (this message is harmless) Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-UnityScript.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Assembly-UnityScript.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/UnityEngine.UI.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/UnityEngine.UI.dll into Unity Child Domain Platform assembly: /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Photon3Unity3D.dll (this message is harmless) Loading /private/var/mobile/Containers/Bundle/Application/FF2B6C79-B342-4913-84DC-2F3B2C570684/BOSS.app/Data/Managed/Photon3Unity3D.dll into Unity Child Domain - Completed reload, in 0.058 seconds WARNING: no native support for texture format 5, converting to 4! WARNING: no native support for texture format 5, converting to 4! SaveHero!
(Filename: /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 49)

Now When I execute the save function I get this Exception, followed by these messages:

ExecutionEngineException: Attempting to JIT compile method 'heroSave__TypeMetadata:.ctor ()' while running with --aot-only.

at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in unknown>:0 Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in unknown>:0 at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in unknown>:0 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in :0
at System.Activator.CreateInstance (System.Type type) [0x00000] in :0 at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.CreateMemberTypeMetadata (System.Type type) [0x00000] in :0 at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData (System.Object obj, System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata, System.Object& data) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObject (System.IO.BinaryWriter writer, Int64 id, System.Object obj) [0x00000] in :0 at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance (System.IO.BinaryWriter writer, System.Object obj, Boolean isValueObject) [0x00000] in unknown>:0 at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects (System.IO.BinaryWriter writer) [0x00000] in :0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph (System.IO.BinaryWriter writer, System.Object obj, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in unknown>:0 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in unknown>:0 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) [0x00000] in :0 at GameControl.SaveHero () [0x00000] in :0 at UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) [0x00000] in :0 at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in :0 at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in :0 at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in :0
at UnityEngine.UI.Button.Press () [0x00000] in :0
at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in unknown>:0 at UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in unknown>:0 at UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00000] in unknown>:0 UnityEngine.Debug:Internal_LogException(Exception, Object) UnityEngine.Debug:LogException(Exception) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents() UnityEngine.EventSystems.TouchInputModule:Process() UnityEngine.EventSystems.EventSystem:Update() (Filename: Line: -1)

Here is my script which deals with Save and Load:

using UnityEngine; using System.Collections; using System.Runtime.Serialization.Formatters.Binary; using System.IO;

 public class GameControl : MonoBehaviour {
     
     public static GameControl control;
         
             public int level;
             public int EXP;
             public int baseHealth;
             public int baseDefense;
             public int baseHealthRegen;
             public int baseDamageBonus;
         
         
             
             void Awake () {
             
         
                 if (control == null){
                     DontDestroyOnLoad(gameObject);
                     control = this;
                 }
                 else if (control != this){
                     Destroy(gameObject);
                 }
             }
         
             
             
             
             public void SaveHero(){
         
                 Debug.Log("SaveHero!");
         
                 BinaryFormatter bf = new BinaryFormatter();
                 FileStream file = File.Create(Application.persistentDataPath + "/HeroSaveDataNew.dat");
         
         
         
             
         
                 heroSave data = new heroSave();
         
                 data.baseHealth = baseHealth;
                 data.baseDamageBonus = baseDamageBonus;
                 data.baseDefense = baseDefense;
                 data.baseHealthRegen = baseHealthRegen;
                 data.EXP = EXP;
                 data.level = level;
         
         
                 bf.Serialize(file, data);
                 file.Close();
         
             }
             public void LoadHero(){
         
                 if (File.Exists(Application.persistentDataPath + "/HeroSaveDataNew.dat")){
                     BinaryFormatter bf = new BinaryFormatter ();
                     FileStream file = File.Open (Application.persistentDataPath + "/HeroSaveDataNew.dat", FileMode.Open);
         
                     heroSave data = (heroSave) bf.Deserialize(file);
                     file.Close();
         
                     baseHealth = data.baseHealth;
                     baseDamageBonus = data.baseDamageBonus;
                     baseDefense = data.baseDefense;
                     baseHealthRegen = data.baseHealthRegen;
                     EXP = data.EXP;
                     level = data.level;
         
                     /*heroDataScript.baseHealth = data.baseHealth;
                     heroDataScript.baseDamageBonus = data.baseDamageBonus;
                     heroDataScript.baseDefense = data.baseDefense;
                     heroDataScript.baseHealthRegen = data.baseHealthRegen;
                     heroDataScript.EXP = data.EXP;
                     heroDataScript.level = data.level;*/
         
                 }
         
             }
         
         
         
         }
         
         [System.Serializable]
         class heroSave {
         
             public int level;
             public int EXP;
             public int baseHealth;
             public int baseDefense;
             public int baseHealthRegen;
             public int baseDamageBonus;
         
             public heroSave(){
                 level = 0;
                 EXP = 0;
                 baseHealth = 0;
                 baseDefense = 0;
                 baseHealth = 0;
                 baseHealthRegen = 0;
                 baseDamageBonus = 0;
             }
         
         }



I found similar problems on the internet, but many solutions are 4 years and older and mostly deal with older unity bugs. Many People said that this error is caused by generic types, but as far as I understand the principles of generic types I don´t use any. Here on the unity Page under troubleshooting, they say that I should use a dummy method to force AOT Compile, but I don´t understand what I should do (link text).

I hope that someone can help me find the problem.

If necessary i can provide more code, but this should be the essential one.

Thank you very much,

Frank_O

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by IDreadnought · Dec 19, 2014 at 07:10 AM

I had similar problems when trying to save data on iOS. Similarly to your situation here, the code worked in the editor and on android but threw errors on ios.

This is what I would try:

  • Add this code in the awake of a script that is run before any loading/saving takes place

    if (Application.platform == RuntimePlatform.IPhonePlayer) { Environment.SetEnvironmentVariable ("MONO_REFLECTION_SERIALIZER", "yes"); }

(for explanation of code read here: http://answers.unity3d.com/questions/30930/why-did-my-binaryserialzer-stop-working.html)

  • If that doesn't work I'd recommend doing some changes in the code you are using to serialize/deserialize. I tried to document the whole process here if you are interested: http://2foldgames.com/2014/12/fixing-jit-errors-saving-complex-data-ios-devices/

I'm a little surprised you are having problems because like you said you are not saving generic/complex types. Either way, I hope this helps.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by chris.malloy · Apr 23, 2015 at 08:34 PM

Had the same problem, this fixed mine. http://answers.unity3d.com/questions/286551/serialization-reflection-exception-on-iphone.html?sort=oldest

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Fixing AOT errors in iOS with BinaryWriter 2 Answers

ios: 2 function calls on the same interface, one working... the other function call doing literally nothing 0 Answers

My Generic function using LINQ(orderBy thenBy)Not working on IOS 1 Answer

iOS JIT compile error on Generic method called with basic types (int, bool, float) 1 Answer

How to save custom binary files to iCloud? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges