Skip to content

Commit

Permalink
fix #295
Browse files Browse the repository at this point in the history
  • Loading branch information
gmhevinci committed May 10, 2024
1 parent 9d5a90e commit a4d3788
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,47 @@ public override void Update()
// Check error
if (CacheBundle == null)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(LastError);

// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{
var result = CacheSystem.VerifyingRecordFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
if (result != EVerifyResult.Succeed)
if (result == EVerifyResult.Succeed)
{
// 说明:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
// 大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
byte[] fileData = FileUtility.ReadAllBytes(FileLoadPath);
if (fileData != null && fileData.Length > 0)
CacheBundle = AssetBundle.LoadFromMemory(fileData);
if (CacheBundle == null)
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Failed to load assetBundle from memory : {MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(LastError);
}
else
{
_steps = ESteps.Done;
Status = EStatus.Succeed;
}
}
else
{
YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}");
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}";
YooLogger.Error(LastError);
CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
}
}
else
{
_steps = ESteps.Done;
Status = EStatus.Failed;
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(LastError);
}
}
else
{
Expand Down

0 comments on commit a4d3788

Please sign in to comment.