- Home /
Using LoadFromCacheOrDownload causes iOS to freeze/stall
We have the below code. On Android, the code reports a smooth progress from 0 to 1. On iOS, it jumps straight from 0 to 1. This is also exhibited in the foreground as when we load the asset bundle for the first time the whole app freezes until the bundle successfully loads.
A couple of things to consider:
The problem is iOS specific. it works on every other platform. -we do not ship for webplayer
It successfully loads the assets on iOS - so definitely built for the platform
We download assets over the internet in this particular situation, so we are not loading from streaming assets
When we download, we save to a location on disk. Only after the content is 100% downloaded do we then load the bundle.
Said another way: WWW.LoadFromCacheOrDownload is given a local path to load the bundle from
Line 10 is yield every frame NOT every cpu cycle. So it is not maxing out the CPU.
To reiterate: The below code loads the bundle correctly - it just does not report on progress in a granular way AND the app freezes while loading the bundle
What we would prefer to see is a loading process that is smoother - allowing us to at least show a graduated progress bar or whirly gig.
Why is this? Is there anything we can to do mitigate?
var threadPriority = priority == AssetPriority.Foreground ? ThreadPriority.High : ThreadPriority.Low;
Application.backgroundLoadingPriority = threadPriority;
using (var www = WWW.LoadFromCacheOrDownload(url, 1)) {
Trace.Log(string.Format("{0} {1} Priority: {2}", LocalPackagePath, ContainerPath, priority));
www.threadPriority = threadPriority;
Application.backgroundLoadingPriority = www.threadPriority;
Trace.LogDiag(string.Format("{0} STARTING LoadFromCacheOrDownload", LocalPackagePath));
Script.StartCoroutine(RunWWW(www));
do
{
yield return 0;
Trace.LogDiag("Progress: " + www.progress);
} while (!www.isDone && String.IsNullOrEmpty(www.error));
Trace.LogDiag(string.Format("{0} END LoadFromCacheOrDownload", LocalPackagePath));
if (!String.IsNullOrEmpty(www.error) || www.assetBundle == null) {
// we received an error loading the bundle
// as the bundle is local, chances are the bundle is corrupted by something.
// We delete and move on...
Trace.LogError(string.Format("{0} Error loading bundle @ {1}: {2}", LocalPackagePath, ContainerPath, (String.IsNullOrEmpty(www.error) ? "Unknown" : www.error)));
yield break;
}
Bundle = www.assetBundle;
Bundle.name = ContainerPath;
}
... and:
private IEnumerator RunWWW(WWW www)
{
yield return www;
}
Does it work properly when you load the Assets from your local Streamed Assetbundles folder (Application.strea$$anonymous$$gAssetsPath) did you ensure the asset bundles you load are built for iOS properly rather than for Android? Have you set a correct CrossDomain.xml (probably yes as it works for Android, but you never know)
Isn't the line 10 do loop just maxing out the CPU?
To answer your questions:
The problem is iOS specific. it works on every other platform.
I thought CrossDomain.xml is important for Webplayer - we do not ship for webplayer
It successfully loads the assets on iOS - so definitely built for the platform
We download assets over the internet in this particular situation, so we are not loading from strea$$anonymous$$g assets
Line 10 is yield every frame NOT every cpu cycle. So it is not maxing out the CPU.
For me this looks like a bug. Please create a $$anonymous$$imal reproducible and file a bug report!
We are getting hit by this bug also. I reported the bug along with a simple demo project, bug #684964.
Answer by David-Berger · Apr 13, 2015 at 04:37 PM
I reproduced and verified the issue based on #684964. At the moment this behaviour is by design, we might however review it and see if we can change it in future! Thanks for bringing this to our attention.
We are facing the exact problem. Has there been any progress in fixing this issue?
It's on our investigate list and has developer attention, but no ETA yet.
@cristivp @timothykimball this should be fixed in the latest 5.4 beta. Please give it a go.
Answer by Dave-Hampson · Feb 11, 2015 at 09:03 PM
I've seen a situation like this before where it was actually the server not sending the 'Content-Length' parameter, but only to a particular device (iOS if I remember correctly).
Odd, and completely confusing when diagnosing the problem! Might be worth either trying a different http server where you can view the headers, or getting a packet sniffer to rule this out.
We download via the server and save locally BEFORE loading. We then load per the code above. I have revised the description to include this information.
Ok not the situation I've seen then. One course of action would be to file a bug if you think that you have a good repro case for the iOS version being broken.
Answer by nanusorn · Jan 26, 2017 at 08:47 AM
Finally, this attached url fixed above issue I also faced. https://forum.unity3d.com/threads/appname-was-compiled-with-optimization-stepping-may-behave-oddly-variables-may-not-be-available.372705/
Your answer
Follow this Question
Related Questions
networking, iPhone ... cellular / 3G woes ?? 1 Answer
Unity 3d Network dies on Android 0 Answers
Image-based Level Generator having problems 0 Answers
Bump API for Unity 4 0 Answers
Why can Android send commands via NetworkManager but iOS cannot? 0 Answers