Cysharp / UniTask

Provides an efficient allocation free async/await integration for Unity.
MIT License
7.63k stars 784 forks source link

unityFramework?.pause(true) throw null pointer exceptions #597

Open FrenziedAI opened 1 week ago

FrenziedAI commented 1 week ago

When calling unityFramework?.pause(true) to pause Unity from iOS and then calling unityFramework?.pause(false) to resume it, if there are UniTask code snippets that are currently executing, they may throw null pointer exceptions after resuming, while not pausing Unity does not cause this issue.

FrenziedAI commented 1 week ago

This code snippet

Debug.Log("LoadThuman " + bornPoint.ToString() + Button_Test.ToString() + this.ToString() + obj.ToString() + newAvatarData.ToString() + Instance.ToString() + UIMgr.Instance.ToString() + CommonData.m_Player.ToString());

Where: bornPoint and Button_Test are GameObject references of this on the Inspector, obj is retrieved via GameObject.Find("bornPoint");, newAvatarData is an instance that is created before the await statement in a task, Instance refers to a static object of this, UIMgr.Instance and CommonData.m_Player are static instances of other objects.

Under normal conditions (when iOS is not paused), the output is LoadThumanbornPoint (UnityEngine.Transform)Button_Test (UnityEngine.UI.Button)UIWardrobe (Tsl.Ymkj.Partner.UIWardrobe)bornPoint (UnityEngine.GameObject)THumanAvatarVoUIWardrobe .

However, under circumstances when iOS is paused, there is a probability that the output will be LoadThumannullnullnullbornPoint (UnityEngine.GameObject)THumanAvatarVoUIWardrobe (Tsl.Ymkj.Partner.UIWardrobe)UIMgr (Tsl.Ymkj.Partner.UIMgr).

I have not yet pinpointed the exact moment where this gets lost.

FrenziedAI commented 1 week ago

image

UniTask Test4 UIWardrobe (Tsl.Ymkj.Partner.UIWardrobe)UniTask Test4 UIWardrobe (Tsl.Ymkj.Partner.UIWardrobe) UniTask Test5 null

UniTask Test4 UIWardrobe (Tsl.Ymkj.Partner.UIWardrobe) Tsl.Ymkj.Partner.THumanManager:DownLoadAssetBundle(String, String, UIWardrobe) Tsl.Ymkj.Partner.<LoadAsync>d__54:MoveNext() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder1:Start(d54&) Tsl.Ymkj.Partner.THumanManager:LoadAsync(UIWardrobe, THumanAvatarVo, Transform, String, Boolean, Boolean) Tsl.Ymkj.Partner.d40:MoveNext() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder:Start(d40&) Tsl.Ymkj.Partner.UIWardrobe:LoadThuman(String) Tsl.Ymkj.Partner.d3:MoveNext() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask1:SetResult() Tsl.Ymkj.Partner.<UpdateWardrobeDataAll>d__7:MoveNext() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask1:Run() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask1:SetResult() Tsl.Ymkj.Partner.<UpdateWardrobeData>d__10:MoveNext() Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask1:Run() System.Diagnostics.StackTrace:init_frames(Int32, Boolean) UnityEngine.StackTraceUtility:ExtractStackTrace() System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Runtime.CompilerServices.MoveNextRunner:Run() Cysharp.Threading.Tasks.UniTaskCompletionSourceCore1:TrySetResult(TResult) Cysharp.Threading.Tasks.UniTaskCompletionSourceCore1:TrySetResult(TResult) Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1:TrySetResult(TResult)

d__0:MoveNext() Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1:TrySetResult(TResult) d__7:MoveNext() Cysharp.Threading.Tasks.UniTaskCompletionSource`1:TrySignalCompletion(UniTaskStatus) System.Threading.Tasks.Task:Execute() System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean) System.Threading.Tasks.Task:ExecuteWithThreadLocal(Task&) System.Threading.Tasks.Task:ExecuteEntry(Boolean) UnityEngine.WorkRequest:Invoke() UnityEngine.UnitySynchronizationContext:Exec() The referenced script on this Behaviour (Game Object 'Main Camera') is missing! Unloading 3 Unused Serialized files (Serialized files now loaded: 8) UnloadTime: 3.634542 ms [UnityToNativeJson -> {"methodName":"EnterMainScense","content":""} UnityEngine.StackTraceUtility:ExtractStackTrace() UnityToNative:UnityToNativeInvokeMethod(String, String) 2024-06-27 14:03:27 [unity debug] : 收到U3D的消息: {"methodName":"EnterMainScense","content":""} GetUserDigitalPersonInfo semaphoreSlim WaitAsync Tsl.Ymkj.Partner.GetMetahumanInfo:GetUserDigitalPersonInfo() Tsl.Ymkj.Partner.GetMetahumanInfo:Start() System.Diagnostics.StackTrace:init_frames(Int32, Boolean) UnityEngine.StackTraceUtility:ExtractStackTrace() Unloading 2 unused Assets to reduce memory usage. Loaded Objects now: 7630. Total: 5.003959 ms (FindLiveObjects: 0.423625 ms CreateObjectMapping: 0.207208 ms MarkObjects: 4.339917 ms DeleteObjects: 0.033167 ms) UniTask Test5 null `
FrenziedAI commented 1 week ago

After the line await unityWebRequest.SendWebRequest(); the references within the task (TSK) seem to be lost.