(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 ][1]). 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][2]).
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
[1]: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading
[2]: http://docs.unity3d.com/Manual/TroubleShootingIPhone.html
↧