iOS simulator, error when load resource
Hello. I have simple app which looks like a comics. It just loads and shows images. There is around 300 images. When I left only first ten images - app runs and works nicely in iOS simulator, but when I built app with all of images - it crashes when trying to load images above second image, i mean third, fourth image and so on. Here is code of the method in which I try to load images and which gives the crash.
public void LoadResources(App app)
{
Debug.Log("start load resources");
try {
BGArt = (Sprite)Resources.Load(app.model.pathTrialImages + BackgroundArt, typeof(Sprite));
FAArt = (Sprite)Resources.Load(app.model.pathTrialImages + ForeAddedArt, typeof(Sprite));
Debug.Log(app.model.pathTrialImages + BackgroundArt + " " + BGArt);
Debug.Log(app.model.pathTrialImages + ForeAddedArt + " " + FAArt + "\n");
bgAmbientLoop = (AudioClip)Resources.Load(app.model.pathTrialMusic + BGAmbientLoop, typeof(AudioClip));
if (BGAmbientLoop != "previous kept" && !string.IsNullOrEmpty(BGAmbientLoop) && !bgAmbientLoop)
bgAmbientLoop = app.model.tempAudio;
bgMusicLoop = (AudioClip)Resources.Load(app.model.pathTrialMusic + BGMusicLoop, typeof(AudioClip));
if (!string.IsNullOrEmpty(BGMusicLoop) && !bgMusicLoop)
bgMusicLoop = app.model.tempAudio;
bgVoiceLoop = (AudioClip)Resources.Load(app.model.pathTrialMusic + BGVoiceLoop, typeof(AudioClip));
if (!string.IsNullOrEmpty(BGVoiceLoop) && !bgVoiceLoop)
bgVoiceLoop = app.model.tempAudio;
vfxSound = (AudioClip)Resources.Load(app.model.pathTrialMusic + VFXSound, typeof(AudioClip));
if (!string.IsNullOrEmpty(VFXSound) && !vfxSound)
vfxSound = app.model.tempAudio;
musicSound = (AudioClip)Resources.Load(app.model.pathTrialMusic + MusicSound, typeof(AudioClip));
if (!string.IsNullOrEmpty(MusicSound) && !musicSound)
musicSound = app.model.tempAudio;
voiceSound = (AudioClip)Resources.Load(app.model.pathTrialMusic + VoiceSound, typeof(AudioClip));
if (!string.IsNullOrEmpty(VoiceSound) && !voiceSound)
voiceSound = app.model.tempAudio;
}
catch(System.Exception e)
{
Debug.Log(e.Message);
}
}
And here is the last part of XCODE's log, when it gives me the error
start load resources
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
PageModel:LoadResources(App)
FoGModel:LoadPages(Int32)
FoGController:OnNotification(FoGNotification, Object, Object[])
App:Notify(FoGNotification, Object, Object[])
ButtonView:OnPointerClick(PointerEventData)
UnityEngine.UI.Slider:UnityEngine.UI.ICanvasElement.get_transform()
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
PageView:OnDestroy()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModule:Process()
PageView:OnDestroy()
UnityEngine.EventSystems.EventSystem:Update()
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 64)
The file '/Users/admin/Library/Developer/CoreSimulator/Devices/0FD32B7D-323C-440F-A578-66D553AD4B97/data/Containers/Bundle/Application/EE7E8A00-DA77-4DFE-B23A-5365B98D3335/TheFallOfGyes.app/Data/resources.assets' is corrupted! Remove it and launch unity again!
[Position out of bounds!]
UnityEngine.Resources:Load(String, Type)
PageModel:LoadResources(App)
FoGModel:LoadPages(Int32)
FoGController:OnNotification(FoGNotification, Object, Object[])
App:Notify(FoGNotification, Object, Object[])
ButtonView:OnPointerClick(PointerEventData)
UnityEngine.UI.Slider:UnityEngine.UI.ICanvasElement.get_transform()
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
PageView:OnDestroy()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModule:Process()
PageView:OnDestroy()
UnityEngine.EventSystems.EventSystem:Update()
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
[/Users/builduser/buildslave/unity/build/Runtime/Serialize/SerializationCaching/CachedReader.cpp line 235]
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Serialize/SerializationCaching/CachedReader.cpp Line: 235)
The file '/Users/admin/Library/Developer/CoreSimulator/Devices/0FD32B7D-323C-440F-A578-66D553AD4B97/data/Containers/Bundle/Application/EE7E8A00-DA77-4DFE-B23A-5365B98D3335/TheFallOfGyes.app/Data/resources.assets' is corrupted! Remove it and launch unity again!
[Position out of bounds!]
UnityEngine.Resources:Load(String, Type)
PageModel:LoadResources(App)
FoGModel:LoadPages(Int32)
FoGController:OnNotification(FoGNotification, Object, Object[])
App:Notify(FoGNotification, Object, Object[])
ButtonView:OnPointerClick(PointerEventData)
UnityEngine.UI.Slider:UnityEngine.UI.ICanvasElement.get_transform()
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
PageView:OnDestroy()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModule:Process()
PageView:OnDestroy()
UnityEngine.EventSystems.EventSystem:Update()
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
[/Users/builduser/buildslave/unity/build/Runtime/Serialize/SerializationCaching/CachedReader.cpp line 241]
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Serialize/SerializationCaching/CachedReader.cpp Line: 241)
TheFallOfGyes(885,0x7da11d4) malloc: *** mach_vm_map(size=1597460480) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Could not allocate memory: System out of memory!
Trying to allocate: 1597459332B with 16 alignment. MemoryLabel: NewDelete
Allocation happend at: Line:0 in Overloaded New
Memory overview
[ ALLOC_DEFAULT ] used: 6801894B | peak: 730920497B | reserved: 6945359B
[ ALLOC_TEMP_JOB ] used: 0B | peak: 0B | reserved: 524288B
[ IOS new_delete ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_GAMEOBJECT ] used: 190449B | peak: 190449B | reserved: 222019B
[ ALLOC_GFX ] used: 79052B | peak: 33760092B | reserved: 83497B
[ ALLOC_PROFILER ] used: 17484B | peak: 18076B | reserved: 53184B
Could not allocate memory: System out of memory!
Trying to allocate: 1597459332B with 16 alignment. MemoryLabel: NewDelete
Allocation happend at: Line:0 in Overloaded New
Memory overview
[ ALLOC_DEFAULT ] used: 6801894B | peak: 730920497B | reserved: 6945359B
[ ALLOC_TEMP_JOB ] used: 0B | peak: 0B | reserved: 524288B
[ IOS new_delete ] used: 0B | peak: 0B | reserved: 0B
[ ALLOC_GAMEOBJECT ] used: 190449B | peak: 190449B | reserved: 222019B
[ ALLOC_GFX ] used: 79052B | peak: 33760092B | reserved: 83497B
[ ALLOC_PROFILER ] used: 17484B | peak: 18076B | reserved: 53184B
UnityEngine.Resources:Load(String, Type)
PageModel:LoadResources(App)
FoGModel:LoadPages(Int32)
FoGController:OnNotification(FoGNotification, Object, Object[])
App:Notify(FoGNotification, Object, Object[])
ButtonView:OnPointerClick(PointerEventData)
UnityEngine.UI.Slider:UnityEngine.UI.ICanvasElement.get_transform()
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
PageView:OnDestroy()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.TouchInputModule:Process()
PageView:OnDestroy()
UnityEngine.EventSystems.EventSystem:Update()
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
Mono.Security.Protocol.Tls.SslStreamBase:OnLocalPrivateKeySelection(X509Certificate, String)
[/Users/builduser/buildslave/unity/build/Runtime/Allocator/MemoryManager.cpp line 980]
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Allocator/MemoryManager.cpp Line: 980)
(lldb)
Does some one know why it occures or how to fix it? UPD: by the way, it loads only images from current chapter. It means that if I have 300 images and in first chapter there are only 10 images then it will loads only 10 images. And I have already done with an experiment - i have left images only for first 14 chapters (124 images) and the app works good...
I think you need to remove the previous picture from the memory when you move to the next picture. Call Resources.UnloadAsset() .
i rewrote the code with Resources.UnloadAsset() after each Resources.Load() but it does not help