From 28c22694bab35a7bcb5451c5a34dea065a3a19f4 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 7 Apr 2022 14:24:09 +0800 Subject: [PATCH] Update AssetSystem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复在资源加载完成回调内释放自身资源句柄时的异常报错。 --- .../Runtime/AssetSystem/Handles/AssetOperationHandle.cs | 5 +---- .../Runtime/AssetSystem/Handles/SceneOperationHandle.cs | 5 +---- .../AssetSystem/Handles/SubAssetsOperationHandle.cs | 5 +---- .../Runtime/AssetSystem/Provider/ProviderBase.cs | 9 +++++++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 7c795ae..d59f27e 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -11,10 +11,7 @@ namespace YooAsset } internal override void InvokeCallback() { - if (IsValid) - { - _callback?.Invoke(this); - } + _callback?.Invoke(this); } /// diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs index 0281f88..5d0ed59 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs @@ -11,10 +11,7 @@ namespace YooAsset } internal override void InvokeCallback() { - if (IsValid) - { - _callback?.Invoke(this); - } + _callback?.Invoke(this); } /// diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs index 2d3486c..8d80f13 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs @@ -10,10 +10,7 @@ namespace YooAsset } internal override void InvokeCallback() { - if (IsValid) - { - _callback?.Invoke(this); - } + _callback?.Invoke(this); } /// diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index 2688acd..fc34823 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -224,9 +224,14 @@ namespace YooAsset } protected void InvokeCompletion() { - foreach (var handle in _handles) + // 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。 + List tempers = new List(_handles); + foreach (var hande in tempers) { - handle.InvokeCallback(); + if (hande.IsValid) + { + hande.InvokeCallback(); + } } _waitHandle?.Set(); }