- Home /
Loading asset from an asset bundle crashes on ios.
Hi all,
I am experiencing very strange behaviour on ios with asset bundles.
I made some asset bundles, which depends to other asset bundles. On ios i download asset bundles using "on demand resources". I am making sure that they are downloading just fine. Also Debug section of Xcode shows that asset bundles downloaded succesfully. To make sure i log contents of asset bundles and see that the asset that i will request are already there. (I check if my asset name is in assetBundle.GetAllAssetNames() and i find it there.)
But when i try to load an asset using assetbundle.loadassetasync or assetbundle.loadasset the game crashes.
This is the crash log
2017-02-28 12:36:38.435420 VM[741:261572] Uncaught exception: NSRangeException: *** -[_NSZeroData getBytes:range:]: range {408687, 7168} exceeds data length 0
(
0 CoreFoundation 0x000000018bce11d0 <redacted> + 148
1 libobjc.A.dylib 0x000000018a71855c objc_exception_throw + 56
2 CoreFoundation 0x000000018bce1100 <redacted> + 0
3 Foundation 0x000000018c710b9c <redacted> + 276
4 VM 0x0000000100dfad8c _ZN16AssetCatalogFile4ReadEyyPvPy + 132
5 VM 0x0000000100dfa8e0 _ZN29AssetCatalogFileSystemHandler4ReadER13FileEntryDatayyPvPy + 76
6 VM 0x0000000100d59660 _ZN12FileAccessor4ReadEyyPvPy + 68
7 VM 0x0000000100d50eb8 _ZN20ArchiveStorageReader15ReadFromStorageEyyPvPy + 196
8 VM 0x0000000100d509ac _ZN20ArchiveStorageReader9ReadBlockEjyyPvPy + 324
9 VM 0x0000000100d4bfa8 _ZN20ArchiveStorageReader4ReadEyyPvPy + 308
10 VM 0x0000000100d4be4c _ZN15ArchiveReadFile4ReadEyyPvPy + 84
11 VM 0x0000000100d4b1b4 _ZN17ArchiveFileSystem4ReadER13FileEntryDatayyPvPy + 44
12 VM 0x0000000100d59660 _ZN12FileAccessor4ReadEyyPvPy + 68
13 VM 0x0000000100d44d38 _ZN4File4ReadEyPvm + 52
14 VM 0x0000000100ab0e80 _ZN24AsyncReadManagerThreaded11ThreadEntryEv + 216
15 VM 0x0000000100ab0c24 _ZN24AsyncReadManagerThreaded17StaticThreadEntryEPv + 12
16 VM 0x0000000100d24f7c _ZN6Thread16RunThreadWrapperEPv + 96
17 libsystem_pthread.dylib 0x000000018ad75850 <redacted> + 240
18 libsystem_pthread.dylib 0x000000018ad75760 <redacted> + 0
19 libsystem_pthread.dylib 0x000000018ad72d94 thread_start + 4
)
2017-02-28 12:36:38.435860 VM[741:261572] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_NSZeroData getBytes:range:]: range {408687, 7168} exceeds data length 0'
I tried the same project on Windows platform. Instead of ODR im using WWW. And it works fine on windows.
Answer by Feyyyyy · Mar 01, 2017 at 11:25 AM
I found solution of this problem. I am writing it here in case some other people suffer from the same problem.
I was using the code below to load asset bundle
OnDemandResourcesRequest request = OnDemandResources.PreloadAsync(new string[] {bundleName })
After this request finishes the operation i was using the next line of code to create asset bundle
AssetBundle.LoadFromFileAsync("res://"+bundleName);
The problem is while i was doing it i was loosing the reference to the "request" object. And after garbage collecting phase that asset bundle i load started giving errors.
I keep the reference to the "request" object at some place and problem solved.
Thank you very much for sharing your solution, that was exactly the same problem I had.
@Visutate in my case I kept a list with all OnDemandResourcesRequest objects and didn't call the Dispose() until I need to unload all assets. Hope that helps!
What do you mean by keeping reference at some place? Is it like referencing it to a field in singleton?
Yes, just like Singleton for example, must be at least one link which not killed (don't use local variable).
Your answer
Follow this Question
Related Questions
Assetbundle memory leaks 0 Answers