Skip to content

Commit 5b46177

Browse files
committed
fix(UI资源加载): 增加Resources.Load失败时的错误处理
在UI资源加载过程中,当Resources.Load返回null时,之前没有处理这种情况,可能导致后续代码出现空引用异常。现在添加了空值检查,并在加载失败时调用LoadAssetFailureCallback返回错误信息。
1 parent 55c2a73 commit 5b46177

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Runtime/UIManager.Open.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ private async Task<IUIForm> InnerLoadUIFormAsync(string uiFormAssetPath, Type ui
105105
{
106106
// 从Resources 中加载
107107
var original = (GameObject)Resources.Load(assetPath);
108+
if (original == null)
109+
{
110+
return LoadAssetFailureCallback(assetPath, $"Resources.Load failed for path: {assetPath}", openUIFormInfo);
111+
}
108112
var gameObject = UnityEngine.Object.Instantiate(original);
109113
gameObject.name = uiFormAssetName;
110114
return LoadAssetSuccessCallback(assetPath, gameObject, 0, openUIFormInfo);

0 commit comments

Comments
 (0)