Skip to content

Commit

Permalink
fix: AssetBundle can be loaded only once (#309)
Browse files Browse the repository at this point in the history
* fix(sample): invalid AssetBundle path

* fix(sdk): load AssetBundle only once
  • Loading branch information
homuler committed Oct 10, 2021
1 parent 10fba23 commit 702434d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Assets/Mediapipe/Samples/Common/Scripts/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private IEnumerator Start()
{
case AssetLoaderType.AssetBundle:
{
AssetLoader.Provide(new AssetBundleResourceManager(Path.Combine(Application.streamingAssetsPath, "mediapipe")));
AssetLoader.Provide(new AssetBundleResourceManager("mediapipe"));
break;
}
case AssetLoaderType.StreamingAssets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,9 @@ public override bool IsPrepared(string name)
return File.Exists(path);
}

private AssetBundle _assetBundle;
private AssetBundle assetBundle
{
get => _assetBundle;
set
{
if (_assetBundle != null)
{
_assetBundle.Unload(false);
}
_assetBundle = value;
}
}

private AssetBundleCreateRequest _assetBundleReq;
private AssetBundle assetBundle => _assetBundleReq?.assetBundle;

public void ClearAllCacheFiles()
{
Expand All @@ -66,15 +56,14 @@ public IEnumerator LoadAssetBundleAsync()
yield break;
}

var bundleLoadReq = AssetBundle.LoadFromFileAsync(_AssetBundlePath);
yield return bundleLoadReq;
// No need to lock because this code can be run in main thread only.
_assetBundleReq = AssetBundle.LoadFromFileAsync(_AssetBundlePath);
yield return _assetBundleReq;

if (bundleLoadReq.assetBundle == null)
if (_assetBundleReq.assetBundle == null)
{
throw new IOException($"Failed to load {_AssetBundlePath}");
}

assetBundle = bundleLoadReq.assetBundle;
}

public override IEnumerator PrepareAssetAsync(string name, string uniqueKey, bool overwrite = true)
Expand Down

0 comments on commit 702434d

Please sign in to comment.