- Home /
Quit application while downloading with www.loadfromcacheordownload makes application crash
First, I have successfully downloaded assets bundles with this function
using (WWW www = WWW.LoadFromCacheOrDownload(GetUrlFromServer(url), version))
{
// Progress slider
GameObject loader = new GameObject();
loader.name = "TempAssetBundleLoader";
loader.tag = "bundleloader";
AssetBundleSlider assetBundleSlider = loader.AddComponent<AssetBundleSlider>();
assetBundleSlider.www = www;
if (_isSlideOn)
assetBundleSlider.CreateSlider();
yield return www;
if (www.error != null)
throw new System.Exception("WWW download:" + www.error);
Debug.Log("Downloaded bundle");
}
AssetBundleSlider presents download progress like this:
void Update()
{
if (www != null && !www.isDone && downloadSlider != null)
{
int percent = (int)(www.progress * 100);
Debug.Log(percent + " %");
}
if (www.progress == 1)
{
Destroy(gameObject);
Destroy(downloadSlider);
}
}
When downloading is happening, i try to interrupt it:
When I quit application on ios and go back, app freezes.
When I quit application on editor, it prompts "Moving file failed" message. I try to call www.Dispose() on AssetBundleSlider but it makes my editor crashes:
void OnApplicationQuit() { if (www != null && !www.isDone) { www.Dispose(); www = null; System.GC.Collect(); } }
How can I manage to stop downloading and release downloading caches on application quit?
Any of these similar threads help?
http://answers.unity3d.com/questions/23071/preloading-asset-bundles-by-unloading-them-after-d.html
http://answers.unity3d.com/questions/35231/loading-webplayer-builds-via-wwwloadfromcacheordow.html
I'm afraid those are not similar. I want to force app to quit (by stop play mode on editor or close app on ios) while downloading asset bundles (interrupting download process), start app again, start download again without making any error.
When the app quits, the download will stop. You can clean the AssetBundles cache with this:
http://docs.unity3d.com/ScriptReference/Caching.CleanCache.html
When I quit application on ios and go back, app freezes.
That's strange, not sure whether it's caused by your app corrupting something, or a Unity bug.
@unimechanic CleanCache will clean all my caches. That is not what I should do. Will the asset is caching while downloading? And when I start app back, it loads this broken asset? This runs fine on Android. Not sure what happen on iOS caching system.
Here is very good plugin to download files in GBs without any crashing specially on iOS. https://assetstore.unity.com/packages/tools/network/large-file-downloader-cross-platform-92128