Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug [Addressables 1.17.13] get_frameCount can only be called from the main thread.

Discussion in 'Addressables' started by iamarugin, Mar 20, 2021.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    Just updated Addressables from 1.15.1. Trying to launch the game in the Editor in the fast mode.
    Getting a bunch of exception in the console:

    Code (CSharp):
    1. UnityException: get_frameCount can only be called from the main thread.
    2. Constructors and field initializers will be executed from the loading thread when loading a scene.
    3. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
    4. UnityEngine.AddressableAssets.Utility.ResourceManagerDiagnostics.OnResourceManagerDiagnosticEvent (UnityEngine.ResourceManagement.ResourceManager+DiagnosticEventContext eventContext) (at Library/PackageCache/com.unity.addressables@1.17.13/Runtime/Utility/ResourceManagerEventCollector.cs:95)
    5. UnityEngine.ResourceManagement.ResourceManager.PostDiagnosticEvent (UnityEngine.ResourceManagement.ResourceManager+DiagnosticEventContext context) (at Library/PackageCache/com.unity.addressables@1.17.13/Runtime/ResourceManager/ResourceManager.cs:303)
    6. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].IncrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.17.13/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:145)
    7. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1+<>c__DisplayClass45_0[TObject].<get_Task>b__0 (System.Object o) (at Library/PackageCache/com.unity.addressables@1.17.13/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:248)
    8. System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    9. System.Threading.Tasks.Task.Execute () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    10. --- End of stack trace from previous location where exception was thrown ---
    11. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    12. System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    13. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    14. System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    15. System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    16. Services.AddressableHelper+<LoadAssetAsync>d__4`1[T].MoveNext () (at Assets/Scripts/Services/AddressableHelper.cs:47)
    17. --- End of stack trace from previous location where exception was thrown ---
    18. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    19. System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    20. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    21. System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    22. System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    23. Services.SpriteCache+<Load>d__10.MoveNext () (at Assets/Scripts/Services/Cache/SpriteCache.cs:61)
    24. --- End of stack trace from previous location where exception was thrown ---
    25. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    26. System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    27. UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <42a5878ce129403083acccf18e43363f>:0)
    28. UnityEngine.UnitySynchronizationContext:ExecuteTasks()
    29.  
     
    KAJed likes this.
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
    If you haven't yet, could you file a bug report for us on this?
     
  3. newatlanta19006

    newatlanta19006

    Joined:
    Feb 23, 2019
    Posts:
    13
    I am seeing the same thing. For me I can't do any LoadAssetAsync calls (or really anything) with Addressables because of this.
     
  4. MarkvDrimmelen

    MarkvDrimmelen

    Joined:
    Oct 13, 2017
    Posts:
    13
    I've had the same issue after upgrading to 1.17.13 and all it took to get this exception was instantiating something. The exception is no longer thrown when the Send Profiler Events setting is disabled, so that's what I'm doing until this is fixed.
     
    Noblauch likes this.
  5. newatlanta19006

    newatlanta19006

    Joined:
    Feb 23, 2019
    Posts:
    13
    Oh, thanks for the tip Mark, i'll try that. I wish Addressables quality control was a bit better! Upgrading Addressables is always an incredible pain due to major bugs.
     
    chrismarch likes this.
  6. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    Yes, every single update is a pain. Every time something breaks.
     
    Prince_of_Persia likes this.
  7. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    I get the same error if I use await handle.task, if I use yield or WaitForCompletion() I don't get it
     
  8. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    Reproduced in 1.17.15
     
  9. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    465
    also running into this into the editor, doesn't matter if I turn off profiler events in the addressables settings
     
  10. sTs_28

    sTs_28

    Joined:
    Jul 15, 2015
    Posts:
    8
    I use addressables like a year or more and all the time every update is the same. You try to fix bug create new bugs, ask peoples send reports. Its not like a hard to test bug, but it seems like package is not testing before release, and make tests on real users. Maybe you shoud test package harder cause it hurts for games with million player wait when some minor bug will be fixed, and risk on real players when update plugin

    P.S. OMG you even remove preview mark from plugin, when users cant even use plugin, and get errors like that its not look like stable version (1.17.15)
     
    Last edited: Mar 31, 2021
    wuGor likes this.
  11. EmilieCollard191

    EmilieCollard191

    Joined:
    May 8, 2019
    Posts:
    77
    Hello, does someone have an update on this? Its would be really nice to have that fixe soon. Sync remove a LOT of complexity in our app.
     
  12. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    I'll start with the initial issue. Based on the log, there seems to be an exception thrown by the event collector system if it is somehow triggered off of the main thread. Which lines up with the statement in this thread that turning off "Send Profiler Events" fixes it. It also means this only happens if the callstack is off of the main thread, which is likely why for one user it only happened with the "await task" interface.

    So, based on that info, it would seem:
    1. we can repro this locally, no need for a bug submission.
    2. disabling send Profiler Events seems to be the most straightforward workaround.

    For others running into something different, you may need to create bug against Unity with a repro project. Without that I'm not sure what we can do for you. The callstack as included at the start is specifically from "ResourceManagerEventCollector.cs:95". If you have "send profiler events" off, then this won't get hit. Which perhaps means you are running into a similar but different bug.
     
  13. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    863
    Thank you for the clarification!
     
  14. wuGor

    wuGor

    Joined:
    Jun 12, 2018
    Posts:
    4
    Agree! so many pain while using addressable.
     
  15. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    162
    Nothing scares me as much as Addressables updates. Either it's some bug or a functionality has changed drastically (again).
    I get this bug in 1.17.17. It's marked as a Release version, but it really shouldn't.
     
    Noblauch and wuGor like this.
  16. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    Lol each addressable version is a new adventure... you get new bug, some fix, some old bug that show back... when you are lucky you even get process change...
    1.17.17 with slight modification do what I need at the moment. not doing any upgrade or touching it again unless found something that break it, and that I can't fix myself using their code
     
    wuGor likes this.
  17. EmilieCollard191

    EmilieCollard191

    Joined:
    May 8, 2019
    Posts:
    77
    I found that profiler event change only if you build the addressable.
     
  18. EmilieCollard191

    EmilieCollard191

    Joined:
    May 8, 2019
    Posts:
    77
    Hello, 1.18.2 has release but the bug is not fixed yet. When will this be fixed?
     
  19. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Our fix is done and will be in the next package release. Likely 1.18.4.
     
  20. jperry_oddgames

    jperry_oddgames

    Joined:
    Sep 18, 2017
    Posts:
    62
  21. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Just stumbled across this in 1.17.17 as-well while trying to debugging reference counts. Disable the events and rebuilding Addressables made it work again for now.
     
    Last edited: Jun 1, 2021