Benedicht / BestHTTP-Issues

Issue tracking repo for the Best HTTP and all related Unity plugins.
https://assetstore.unity.com/publishers/4137
12 stars 1 forks source link

HTTPUpdateDelegator.Instance is not well managed. #211

Open feraligatr opened 3 days ago

feraligatr commented 3 days ago

BestHTTP version: 3.0.11 Unity 2022.3.51f1 Platform: Android

  1. HTTPUpdateDelegator.UnityApplication_WantsToQuit() is called in HTTPUpdateDelegator.OnDisable(). However the GameObject instance is not set as "DontDestroyOnLoad" anywhere. When scene is switched, UnityApplication_WantsToQuit() will be called by OnDisable(), and IsCreated will be false. If UnityApplication_WantsToQuit() is called again by Application.wantsToQuit, the line "Instance.PingUpdateThread();" will call CheckInstance() again and create a new hidden instance in Unity Editor. And the hidden instance keeps alive even in next "Play mode" session. Suggested Solution: mark the instance as "DontDestroyOnLoad" when it's created.

  2. In HTTPUpdateDelegator.CheckInstance(), it checks whether there's a GameObject named "HTTP Update Delegator". If it exists but without HTTPUpdateDelegator component (like disabled by some scripts so it == null), the code creates a new "HTTP Update Delegator". It will shadow the old object. In my case Setup() is called on old instance but not on the new one. Suggested Solution: Destroy the "HTTP Update Delegator" GameObject if its HTTPUpdateDelegator component == null.

Benedicht commented 2 days ago

GameObject.DontDestroyOnLoad is called on the gameObject from the Setup() method. Setup() is called from Update.

It worked as expected through my tests. Could follow the steps here to collect and send over diagnostic logs from the plugin: Reporting Bugs ?