We have an iOS/Android app that we've created using Unity3D (5.0.2). It is a 2D app that downloads and displays fairly large images from our servers. We are currently in the process of creating a 64-bit build to be in compliance with Apple's new standards for iOS apps (previously we were using 32-bit builds). We've worked through several issues with converting the project over to 64-bit, but we're having trouble with an out of memory error on iPhones/iPads when loading images into 2DTexture objects. However, XCode reports that the project is using between 89-100MB of memory with 150MB free. As we navigate our app, we are not noticing any memory leaks, but it will eventually crash with the out of memory error even though we have added try-catch blocks around the line that is crashing. Here is the code we use to load images from the disk, it crashes on line 9:
if (File.Exists(DataStorage.Instance._persistantImageFilePath + "/" + fileName))
{
myTextByte = File.ReadAllBytes(DataStorage.Instance._persistantImageFilePath + "/" + fileName);
}
if (myTextByte != null)
{
Texture2D myText = new Texture2D(0, 0, TextureFormat.RGB24, false);
myText.LoadImage(myTextByte); //Out of memory exception here
return myText;
}
From the console log:
> **Unloading 3 unused Assets to reduce memory usage. Loaded Objects now:> 1710. Total: 3.629958 ms (FindLiveObjects: 0.192500 ms> CreateObjectMapping: 0.084916 ms> MarkObjects: 3.307000 ms > DeleteObjects: 0.044291 ms) > Game(1544,0x3a71d9dc) malloc: ***> mach_vm_map(size=2859008) 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: 2856948B with 16> alignment. MemoryLabel: Texture> Allocation happend at: Line:370 in > Memory overview [ ALLOC_DEFAULT ]> used: 11820805B | peak: 15785886B |> reserved: 11969898B [ ALLOC_TEMP_JOB> ] used: 0B | peak: 0B | reserved:> 524288B [ IOS new_delete ] used: 0B |> peak: 0B | reserved: 0B [> ALLOC_GAMEOBJECT ] used: 373061B |> peak: 673157B | reserved: 415279B [> ALLOC_GFX ] used: 8291748B | peak:> 17886824B | reserved: 8292774B [> ALLOC_PROFILER ] used: 0B | peak: 0B |> reserved: 0B Could not allocate> memory: System out of memory! Trying> to allocate: 2856948B with 16> alignment. MemoryLabel: Texture> Allocation happend at: Line:370 in > Memory overview [ ALLOC_DEFAULT ]> used: 11820805B | peak: 15785886B |> reserved: 11969898B [ ALLOC_TEMP_JOB> ] used: 0B | peak: 0B | reserved:> 524288B [ IOS new_delete ] used: 0B |> peak: 0B | reserved: 0B [> ALLOC_GAMEOBJECT ] used: 373061B |> peak: 673157B | reserved: 415279B [> ALLOC_GFX ] used: 8291748B | peak:> 17886824B | reserved: 8292774B [> ALLOC_PROFILER ] used: 0B | peak: 0B |> reserved: 0B > System.Collections.Generic.Enumerator:get_Current()> UnityEngine.Texture2D:LoadImage(Byte[])> ImageManager:ReturnTextureFromDisk(String)> BackgroundManager:GetBackground(Prize)> Scroller:SetBackgroundImage(Prize,> GameObject)> Scroller:switchAndAnimateBackground(direction,> Prize) Scroller:SwitchPrize(direction)> Scroller:AnimateAndSwitchPrize()> Scroller:CheckToSeeIfPrizeShouldSwitch()> Scroller:OnEndDrag(PointerEventData)> Assets.Code.Utilities.parentDrag:Invoke(PointerEventData)> TapMeterMilestonMarker:DoneShrinking()> Assets.Code.Utilities.DragClickHelper:OnEndDrag(BaseEventData)> :.ctor()> NativeXMiniJSON.Serializer:SerializeOther(Object)> :.ctor()> :.ctor()> UnityEngine.Events.InvokableCallList:Invoke(Object[])> UnityEngine.Events.UnityEventBase:Invoke(Object[])> :.ctor()> UnityEngine.EventSystems.EventTrigger:Execute(EventTriggerType,> BaseEventData)> UnityEngine.EventSystems.EventTrigger:OnEndDrag(PointerEventData)> UnityEngine.UI.ContentSizeFitter:SetLayoutVertical()> UnityEngine.EventSystems.ExecuteEvents:Execute(IEndDragHandler,> BaseEventData)> :.ctor()> System.Array:InternalArray__IEnumerable_GetEnumerator()> UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject,> BaseEventData, EventFunction`1)> UnityEngine.EventSystems.TouchInputModule:ProcessTouchPress(PointerEventData,> Boolean, Boolean)> UnityEngine.EventSystems.TouchInputModule:ProcessTouchEvents()> UnityEngine.EventSystems.TouchInputModule:Process()> NativeXMiniJSON.Serializer:SerializeOther(Object)> UnityEngine.EventSystems.EventSystem:Update()> System.Collections.Generic.Enumerator:get_Current()**
We've also have occasionally seen it crash when loading with the following console log:
> **Game(1662,0x4b426000) malloc: *** mach_vm_map(size=1048576) failed> (error code=3)> *** error: can't allocate region> *** set a breakpoint in malloc_error_break to debug 2015-06-02> 14:24:51.437 Game[1662:772823]> Uncaught exception: NSMallocException:> Attempt to allocate 1048576 bytes for> NS/CFData failed [ "0 > CoreFoundation > 0x2973b007 + 150", "1 > libobjc.A.dylib > 0x37af8c8b objc_exception_throw + 38",> "2 Foundation > 0x2a4677e1 _NSErrnoMessage + 0", "3 > CoreFoundation > 0x296e6adb + 98", "4 > CoreFoundation > 0x296e6c47 + 322", "5 > CoreFoundation > 0x2964c543 CFDataReplaceBytes + 266", > "6 CoreFoundation > 0x2965aa35 CFDataAppendBytes + 116", > "7 CFNetwork > 0x2918ebf3 + 158", "8 > CFNetwork > 0x2922e0d5 + 60", "9 > CFNetwork > 0x29270cb7 + 14", "10 > libdispatch.dylib > 0x0697f173> _dispatch_call_block_and_release + 10", "11 libdispatch.dylib > 0x06987d67 _dispatch_queue_drain +> 1718", "12 libdispatch.dylib > 0x06981a61 _dispatch_queue_invoke +> 88", "13 libdispatch.dylib > 0x06989b09 _dispatch_root_queue_drain> + 1308", "14 libdispatch.dylib 0x0698ae19 _dispatch_worker_thread3 +> 100", "15 libsystem_pthread.dylib > 0x381cadc1 _pthread_wqthread + 668", > "16 libsystem_pthread.dylib > 0x381cab14 start_wqthread + 8" ]> 2015-06-02 14:24:51.442> Game[1662:772823] *** Terminating app> due to uncaught exception> 'NSMallocException', reason: 'Attempt> to allocate 1048576 bytes for> NS/CFData failed'> *** First throw call stack: (0x2973afef 0x37af8c8b 0x2a4677e1> 0x296e6adb 0x296e6c47 0x2964c543> 0x2965aa35 0x2918ebf3 0x2922e0d5> 0x29270cb7 0x697f173 0x6987d67> 0x6981a61 0x6989b09 0x698ae19> 0x381cadc1 0x381cab14)> libc++abi.dylib: terminating with> uncaught exception of type> NSException**
↧