From 33356cb270ad75413ae5e2f3c19acad678edd407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 4 Dec 2025 20:34:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=B8=80=E4=BA=9B=E9=AB=98?= =?UTF-8?q?=E5=8D=B1=E9=A3=8E=E9=99=A9=E7=9A=84=E4=BB=A3=E7=A0=81=E5=AE=B9?= =?UTF-8?q?=E9=94=99=E6=9C=BA=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperationSystem/AsyncOperationBase.cs | 18 +++++++++++---- .../Provider/ProviderOperation.cs | 23 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs index 793ffca8..457a4f8a 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs @@ -188,11 +188,19 @@ namespace YooAsset // 结束记录 DebugEndRecording(); - //注意:如果完成回调内发生异常,会导致Task无限期等待 - _callback?.Invoke(this); - - if (_taskCompletionSource != null) - _taskCompletionSource.TrySetResult(null); + try + { + _callback?.Invoke(this); + } + catch (Exception ex) + { + YooLogger.Error($"Exception in completion callback: {ex}"); + } + finally + { + if (_taskCompletionSource != null) + _taskCompletionSource.TrySetResult(null); + } } } diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs index 462eaeff..0904e2d1 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderOperation.cs @@ -269,6 +269,7 @@ namespace YooAsset if (_resManager.UseWeakReferenceHandle) { + // TODO 高危风险:如果移除弱引用失败,会导致资源永远无法释放。 if (RemoveWeakReference(handle) == false) throw new System.Exception("Should never get here !"); } @@ -335,11 +336,18 @@ namespace YooAsset List> tempers = _weakReferences.ToList(); foreach (var weakRef in tempers) { - if (weakRef.TryGetTarget(out HandleBase target)) + if (weakRef.TryGetTarget(out HandleBase handle)) { - if (target.IsValid) + if (handle.IsValid) { - target.InvokeCallback(); + try + { + handle.InvokeCallback(); + } + catch (Exception ex) + { + YooLogger.Error($"Exception in completion callback: {ex}"); + } } } } @@ -351,7 +359,14 @@ namespace YooAsset { if (handle.IsValid) { - handle.InvokeCallback(); + try + { + handle.InvokeCallback(); + } + catch (Exception ex) + { + YooLogger.Error($"Exception in completion callback: {ex}"); + } } } }