This commit is contained in:
何冠峰
2026-06-02 10:53:35 +08:00
parent d712a00458
commit 20ae423bbe

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
@@ -72,7 +73,10 @@ namespace YooAsset
// 释放所有资源句柄
if (_options.ReleaseAllHandles)
{
foreach (var provider in _resManager.ProviderDic.Values)
// 注意创建快照因为释放句柄可能触发自动卸载逻辑AutoUnloadBundleWhenUnused
// 进而修改 ProviderDic 容器,导致遍历时抛出 InvalidOperationException。
var snapshot = new List<ProviderOperation>(_resManager.ProviderDic.Values);
foreach (var provider in snapshot)
{
provider.ReleaseAllHandles();
}