mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
完善一些高危风险的代码容错机制。
This commit is contained in:
@@ -188,11 +188,19 @@ namespace YooAsset
|
|||||||
// 结束记录
|
// 结束记录
|
||||||
DebugEndRecording();
|
DebugEndRecording();
|
||||||
|
|
||||||
//注意:如果完成回调内发生异常,会导致Task无限期等待
|
try
|
||||||
_callback?.Invoke(this);
|
{
|
||||||
|
_callback?.Invoke(this);
|
||||||
if (_taskCompletionSource != null)
|
}
|
||||||
_taskCompletionSource.TrySetResult(null);
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
YooLogger.Error($"Exception in completion callback: {ex}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (_taskCompletionSource != null)
|
||||||
|
_taskCompletionSource.TrySetResult(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -269,6 +269,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_resManager.UseWeakReferenceHandle)
|
if (_resManager.UseWeakReferenceHandle)
|
||||||
{
|
{
|
||||||
|
// TODO 高危风险:如果移除弱引用失败,会导致资源永远无法释放。
|
||||||
if (RemoveWeakReference(handle) == false)
|
if (RemoveWeakReference(handle) == false)
|
||||||
throw new System.Exception("Should never get here !");
|
throw new System.Exception("Should never get here !");
|
||||||
}
|
}
|
||||||
@@ -335,11 +336,18 @@ namespace YooAsset
|
|||||||
List<WeakReference<HandleBase>> tempers = _weakReferences.ToList();
|
List<WeakReference<HandleBase>> tempers = _weakReferences.ToList();
|
||||||
foreach (var weakRef in tempers)
|
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)
|
if (handle.IsValid)
|
||||||
{
|
{
|
||||||
handle.InvokeCallback();
|
try
|
||||||
|
{
|
||||||
|
handle.InvokeCallback();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
YooLogger.Error($"Exception in completion callback: {ex}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user