- Home /
Can a big resources.assets file cause issues on iOS ?
Hi,
I'm working on an iOS project, targeting the iPad mini.
I've come to find it handy to put most of the UI textures in the Resources folder and load them with Resources.Load(), instead of assigning them manually in the editor.
Now, I'm facing an odd problem. When running the project from Xcode, it starts the app on the device, showing the launch screen and loading indicator for a while, then closes. Xcode says nothing but "Finished running XXX.app on iPad", like it was the expected behaviour - no error code or what so ever.
I've stripped the project down so that I now only have my welcome screen scene and kept my Resources folder with all unnecessary resources in it. Problem still happens. When I remove the unnecessary resources, the application starts much faster and remains open.
This makes me think the resources.assets file is fully loaded upon start, and that there's some kind of limited time to load it fully before the app stops. What is also weird, is that if I keep running the app multiple time, eventually, it'll open. Letting me think it keeps loading that file from a run to the next.
Can someone bring some light over this please ?
Answer by CgShady · Apr 04, 2013 at 11:29 PM
Ok, I'll try to bring some light over this.
I stripped the project I had problem with so that it contains :
an intro scene file with nothing but a script that loads next level on a touch
a second scene that displays some GUI elements with an OnGUI function in a script
that OnGUI uses a GUISkin, which is loaded from the Resources folder with Resources.Load()
the GUISkin references a few small textures, so far so good..
the Resources folder also contains huge textures, flagged as GUI, NPOT and not compressed (I made them really big on purpose for testing)
Result : A huge resources.asset file (130Mb), two tiny sharedassets0.assets and sharedassets1.assets files (4kb and 5kb). Once loaded, the first screen shows up really quickly. (it doesn't use any of the files from the resources) Then tapping goes to load the next level, wheel ... then app closes
iPad backboardd[27] : Application 'UIKitApplication:com.xxx.yyy[0xcee9]' exited abnormally with signal 9: Killed: 9
My understanding is that the resources.asset file doesn't support partial loading. So when accessing it for a few small files, it will load it all, and get us killed by the system after memory warnings..
I'm now looking at splitting everything in asset bundles to work around this.
Using Asset Bundles works like a charm. I split my resources folder into asset bundles and load assets (textures) async from them. Not been warned about memory so far..
Answer by dannyskim · Feb 26, 2013 at 05:28 PM
Most likely the behavior that your application is inhibiting is because you're running out of RAM / VRAM. Your textures are probably taking up too much space, so either try down res-ing or make sure all your textures are power of 2 to reduce memory waste.
Well, the thing is that those textures are not loaded. All I have is a single Scene, using a few textures from the Resources folder, but not all.
When I manually remove the never used textures, the app runs fine. When I put them back, it just stops, but I don't even get a warning from Xcode either. No $$anonymous$$emory warning, nothing.
Answer by Tarlius · Feb 26, 2013 at 05:45 PM
Resources in Resources are not loaded, but they are (obviously) copied to the device, which will impact how fast your app builds and deploys.
If your program is running out of memory, you'll get flooded with Memory Warnings on the console (they come when you still have space too, its a bit of a black box) and springboard will kill your app.
If you do have any objects in the scene referencing items directly in a resources folder (Ie, a public Texture2D assigned in the editor) they will be loaded at runtime, as will prefabs linked in the editor, and any textures (etc) on the prefabs.
Stupid question, maybe, but did you try turning it off and on again? A lot of XCode's "quirks" can be resolved with a simple close, unplug devices, reopen, replug devices. (I've wasted many hours to have a "serious" problem vanish like this...) Come to think of it, I think I've had that one before >.>;; Another common two are "Could not connect to debugger" and "Could not find executable"
Another trick that sometimes fixes stuff like this is a Clean (Cmd + Shift + K), often mixed in with the above.
I'm nailing it down, and before I post a final answer to this, here are a few things I found about : - resources really seem to be loaded, wether you call them or not - NPOT textures are not compressed at all on iOS, which makes GUI textures eat a lot of RA$$anonymous$$
NPOT textures don't get compressed in the editor either, if you look. Even if you check pvrtc it will still show them as 32bit. As far as I'm aware, this is a limitation with PVRTC, not unity. What most people seem to do for UI textures is bundle them all into one big power-of-two texture (called an atlas) and compress it that way. The space in the texture you don't use is, of course, wasted though :( If you're doing mobile devices, this also lowers your draw calls while will give you a nice FPS boost too.
Answer by Graham-Dunnett · Feb 27, 2013 at 10:16 PM
The documentation is pretty detailed about how to troubleshoot problems running on device. If the application is out of memory, then you'd get an applicationDidReceiveMemoryWarning()
message. Since you do not mention this in your question, I suspect that you are getting killed because the app is taking too long to display the first frame. In this case you'll get a killed by SpringBoard
message in XCode.
I just checked in XCode ; no message about SpringBoard. I also did try adding an in-between scene which loads the next scene with a click of a button. In which case the first screen loads ok, but when trying to load the next it stops the app, with no warning what so ever. I know too little about Resources, is it possible that fetching a resource triggers the loading of the whole asset file ?
Did you check in the Organiser in XCode, or just the console? I think the Organiser sometimes gives you a little more info.
If you load a prefab, it will load everything that that prefab references (see my answer). This includes everything that those things reference (etc), as well as all children, etc. You may need to break things up a little more and load linked resources using Resources.Load as needed.
For example, if you have a factory prefab that holds direct references to every enemy prefab in your game, when you instantiate the factory it will also load all the prefabs and their textures. And if you have a prefab of factories that reference prefabs...
However, since you said you're getting no memory warnings, this might not be the cause of your issue...
Hey Graham, or anyone .. to step back, I have a simpler question.
Is "resources.assets" - in fact - pretty much: "stuff in your Resources/ folder"?
Would you say that is correct?
Cheers!