Search Unity

Bug Using WaitForCompletion freezes app on some mobile devices

Discussion in 'Addressables' started by Xarbrough, Aug 24, 2021.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Our game is very close to release and we've discovered a nasty issue: in some very specific circumstances, using the synchronous Addressables workflow (calling WaitForCompletion on a handle), will cause the Android or iOS app to freeze and never finish loading. It seems like the while loop in the WaitForCompletion implementation spins forever because the operation never finishes, potentially because it is stalled by something else.

    I've already reported the issue (case 1349881), but Unity QA are having issues reproducing the issue on their end, although it happens for me reliably on multiple devices.

    This is why I'm hoping somebody on the forum to give me any pointers what could be going wrong here.

    We've already started just removing as many calls to WaitForCompletion as possible and it fixes the issue happening in those situations, however, some instances are a lot of work to convert to an async style and we've already passed our main QA slot, so we can't simply rewrite all of those systems and hope nothing breaks.

    Any ideas how to deal with this? I was thinking of adding a timout to the WaitForCompletion while loop implementation myself to simply abort after some time, since I'd rather deal with a missing asset thana frozen app. I would hope that then it might also be easier to discover and handle the issue, because so far, everytime QA finds the bug, the device is locked up, I cannot connect a debugger and the log until that point shows no errors.
     
    ununion and phobos2077 like this.
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    I'll flag with the team!
     
  3. unity_shane

    unity_shane

    Unity Technologies

    Joined:
    Jun 3, 2021
    Posts:
    106
    Hi there @Xarbrough, in our newest version just released today (1.19.4) we fixed an issue relating to infinite loops caused by WaitForCompletion, so updating should hopefully fix your issue. That said, if you're reluctant to update addressables versions shortly before your release, you alternatively could simply implement the fix that we did yourself onto your project's addressables package by manually replacing your FastModeInitializationOperation.InvokeWaitForCompletion code and both AsyncOperationHandle.WaitForCompletion functions with those from the new version and see if that fixes the issue, although I personally recommend updating to avoid any hassle. Thank you for your patience and please reach out again if the issue continues to manifest.
     
    apkdev and Xarbrough like this.
  4. hazuhiro

    hazuhiro

    Joined:
    Feb 14, 2019
    Posts:
    34
    @unity_shane
    hi im using addressables latest version 1.19.11 the issue still persist,
    when i use WaitForCompletetion, my phone is freeze,
    any idea why is that?
     
  5. su9257

    su9257

    Joined:
    Jun 13, 2017
    Posts:
    27
    I ran into the same problem with latest version 1.19.11
     
  6. unity_shane

    unity_shane

    Unity Technologies

    Joined:
    Jun 3, 2021
    Posts:
    106
    @hazuhiro, @su9257, could you tell me a little bit more about how you're using WaitForCompletion in this case or even potentially send a bug report with a project that reproduces the issue? I'm not familiar with any known issues involving WaitForCompletion in 1.19.11, so its possible this is a new unreported bug.
     
  7. su9257

    su9257

    Joined:
    Jun 13, 2017
    Posts:
    27
    We have provided a bug example numbered 1378305, looking forward to your reply:)
     
  8. OFGPhil

    OFGPhil

    Joined:
    Feb 9, 2021
    Posts:
    1
    Hi, was there ever any solution to this?

    We are encountering a similar issue on console when using addressables v1.18.11.

    Cheers!
     
    Last edited: Jan 5, 2022
  9. unity_shane

    unity_shane

    Unity Technologies

    Joined:
    Jun 3, 2021
    Posts:
    106
    @OFGPhil, Hi there, I believe we've pushed fixes or closed the tickets for all of the bug reports that arose from this thread thus far - in addition, we've also pushed a few new fixes unrelated to this thread for WaitForCompletion in the time that's passed since the last time this thread was active. I would recommend updating to the newest version of addressables if you're having WaitForCompletion issues, particularly in the case that your freezing is resulting from calling WaitForCompletion on Scenes - truth be told, while we do our best to support WaitForCompletion on Scenes, due to editor limitations (scene loading is inherently asynchronous at the editor level) it is quite difficult to make an airtight implementation of WaitForCompletion for Scene loading. For you, or any other user that might be using WaitForCompletion while loading Scenes, I personally would recommend writing asynchronous scene loading code to minimize the likelihood of running into possible problematic edge cases.
     
  10. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    60
    I found myself in the same situation, and if anyone ever comes to this same problem,
    Attach a debugger to Unity and pause the execution,
    Unity is probably in an infinite while loop.

    My case what that i was doing this :

    Addressables.LoadAssetAsync<T>(typeof(T).Name).WaitForCompletion();

    And it never completed (there was no asset with given name).
     
  11. OndraPaska

    OndraPaska

    Joined:
    Jul 5, 2014
    Posts:
    14
    I'm also still experiencing this issue on Android. WaitForCompletion freezes the app with no error. I'm not loading scenes, only AudioClips.