Super strange issue, and maybe a bug within Unity. In a C# base applicaiton, when downloading an asset bundle from S3 occasionally, on both mobile devices and within the editor, the following error is thrown
AssetBundle client_editor_en_us doesn't have main asset!
UnityEngine.AssetBundle:get_mainAsset()
DownloadBundleState:OnBundleDl(AssetBundle) (at Assets/Scripts/StateMachine/DownloadBundleState.cs:218)
c__Iterator2:MoveNext() (at Assets/Scripts/Managers/AssetBundleDownloadManager.cs:138
Now, the main asset is in fact null/unset but no code is explicitly trying to access the main asset. In fact this bundle is simply passed into a callback function. This callback function is what is actually throwing the error.
Here's the download logic:
using (UnityWebRequest www = new UnityWebRequest (url)) {
// Set up a download handler to pull and asset bundle by version, ignore the check sum
DownloadHandlerAssetBundle downloadHandler = new DownloadHandlerAssetBundle (url, cachedVersion, 0);
www.downloadHandler = downloadHandler;
yield return www.Send ();
if (www.error != null)
throw new Exception ("WWW download had an error:" + www.error);
url = url.Split ('?') [0];
dictAssetBundleRefs.Add (
url + cachedVersion.ToString (),
new AssetBundleRef (url, cachedVersion) {
assetBundle = downloadHandler.assetBundle
}
);
callback (downloadHandler.assetBundle);
}
And here's the callback being invoked:
private void OnBundleDl(AssetBundle bundle) {
AssessmentContentProvider.Instance.Init (bundle);
Blackboard [AssessmentConstants.BLACKBOARD_KEY_DOWNLOADED_CONFIG_VERSION] = 9;
StartBundle ();
} // DownloadBundleState.cs:218
3 very abnormal things:
1. No code tries to access the main asset. Only the AssessmentContentProvider initialization just assigns the variable to a member.
2. The error is reported at the last line of the function, leading me to believe it actually occurs when the function parameter itself is evaluated or after the function is completed outside the main thread.
3. Despite throwing this unhanded exception the app functions totally fine, the asset bundle is set, and we are able to read assets from it.
Because of that I wonder if this a bug within Unity itself, where under certain circumstances it automatically tries to read the main asset. The really crazy, to me, is why normal program execution is totally unaffected by this (relative to where it occurs) critical unhanded exception.
Am I missing something very obvious about the user of bundles within parameters or how unity cleans up reference local reference variables to bundle? Only documentation I can find on the main asset says its optional and must be requested specifically.
↧