Search Unity

Resolved: CurrentThreadIsMainThread() error for Asset Bundle LoadAllAssetsAsync

Discussion in 'Asset Bundles' started by jasonwaltersxyz, Sep 18, 2017.

  1. jasonwaltersxyz

    jasonwaltersxyz

    Joined:
    Jul 16, 2014
    Posts:
    24
    With Unity 2017.1.1, we are now receiving the following error while using LoadAllAssetsAsync.

    Assertion failed: Assertion failed on expression: 'Thread::CurrentThreadIsMainThread()'

    Code (CSharp):
    1.  
    2.     public IEnumerator LoadAssets(string bundleName)
    3.     {
    4.         this.assetsByBundle[bundleName] = new Dictionary<string, GameObject>();
    5.  
    6.         AssetBundle assetBundle = assetBundles[bundleName];
    7.         AssetBundleRequest assetBundleRequest = assetBundle.LoadAllAssetsAsync<GameObject>();
    8.         yield return assetBundleRequest;
    9.         Object[] objects = assetBundleRequest.allAssets;
    10.         foreach (GameObject gameObject in objects)
    11.         {
    12.             this.assetsByBundle[bundleName][gameObject.name] = this.assets[gameObject.name] = gameObject;
    13.         }
    14.     }
    15.  
    Edits:
    Tested with Unity 2017.1.1p2; errors there too. Currently working great on 2017.1.0f3.

    UPDATE:
    This issue has been resolved in Unity patch 2017.2.0p2.
     
    Last edited: Nov 20, 2017
  2. nilsk123

    nilsk123

    Joined:
    Dec 13, 2016
    Posts:
    19
    Been getting this same error on 1.1.f1, everything works but this error appears in log. Seems to sometimes disappear after unity restart.
     
  3. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    Tested with 2017.2.0b8 and 2017.2.0b11, It seems like async loading AssetBundle that contains AnimationClip causes this error.

    These functions are also affected
    - LoadFromFileAsync
    - LoadFromStreamAsync
     
  4. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    Update

    It works on 2017.2.0b5
     
  5. ben-maurin

    ben-maurin

    Joined:
    Apr 7, 2016
    Posts:
    47
    I got the same probleme with 2017.1.1.f1.
     
  6. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    Actually these functions doesn't seems to matter. AssetBundle.LoadAssetAsync and AssetBundle.LoadAllAssetsAsync both causes this error.
     
  7. winterkewl

    winterkewl

    Joined:
    Oct 28, 2011
    Posts:
    53
    Just +1 that i'm seeing the same thing when upgrading from a project that was 5.5.4 now to 2017.1.1f1 that utilizes AssetBundle.LoadAssetAsync the same errors occur.
     
  8. vsattce

    vsattce

    Joined:
    Dec 15, 2014
    Posts:
    6
    I got the same probleme with 2017.1.1.p3.
     
  9. GameTank

    GameTank

    Joined:
    Jul 16, 2014
    Posts:
    2
    I got the same probleme with 2017.2.0f1.

    Assertion failed: Assertion failed on expression: 'Thread::CurrentThreadIsMainThread()'
    0x00000001411AC76B (Unity) StackWalker::GetCurrentCallstack
    0x00000001411AF0FF (Unity) StackWalker::ShowCallstack
    0x0000000141089420 (Unity) GetStacktrace
    0x00000001405956C3 (Unity) DebugStringToFile
    0x0000000140595EA1 (Unity) DebugStringToFile
    0x00000001415F68CF (Unity) AnimationClip::BuildMecanimDataMainThread
    0x00000001415F7993 (Unity) AnimationClip::Transfer<StreamedBinaryRead<0> >
    0x00000001415FE37D (Unity) AnimationClip::VirtualRedirectTransfer
    0x00000001409A57B8 (Unity) SerializedFile::ReadObject
    0x000000014098BE4F (Unity) PersistentManager::ReadAndActivateObjectThreaded
    0x000000014098DE8A (Unity) PersistentManager::LoadObjectsThreaded
    0x00000001406B71DD (Unity) LoadSceneOperation::perform
    0x00000001406B6890 (Unity) PreloadManager::processSingleOperation
    0x00000001406B69FD (Unity) PreloadManager::Run
    0x00000001406B7667 (Unity) PreloadManager::Run
    0x00000001407B1918 (Unity) Thread::RunThreadWrapper
    0x0000000076B359CD (kernel32) BaseThreadInitThunk
    0x0000000076DAA561 (ntdll) RtlUserThreadStart
     
    Last edited: Sep 25, 2017
  10. jasonwaltersxyz

    jasonwaltersxyz

    Joined:
    Jul 16, 2014
    Posts:
    24
    Hey everyone! I created a bug ticket and Unity wrote me today saying it's a duplicate issue that's being worked on. Please have a look and vote on the issue. Thanks!

    https://issuetracker.unity3d.com/is...-with-loadasync-throws-assertion-failed-error

    PS - In the meantime, an alternative that we are exploring is adding the Animator to the necessary GameObjects at runtime. When I'm able to test, I will report my results here.
     
    Last edited: Sep 26, 2017
  11. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    How can a scenario such as loading assets from an asset bundle be so fundamentally broken in a major release version ??
     
  12. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    I know you are not really looking for an answer and just want it fixed, however, creating a build of a user's project data, and ensuring everything builds and loads correctly is a terribly complex problem. I'm giving a talk at Unite Austin that goes into the details of this for those that want more insight, and If you or others may find it interesting, we can see if we can adding the talk to the https://youtube.com/user/Unity3D channel. Just be warned it will be an hour long talk by me, and may be boring (I hope not though).

    In this specific case, this issue was caused by fixing another bug to ensure AnimationClip data was actually being written out to disk correctly for asset bundles to be used by the player. The result though is that if you load that AnimationClip data from an asset bundle in the Editor using Async api's, then it would trigger this assert. So this issue only will occur in the Editor and has no impact on the Player.
     
    tomerpeledNG, dadude123 and liortal like this.
  13. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I will definitely check out that session once it's posted on YouTube.

    I am aware of the fact that certain things are very complex, but i would assume there are tests you perform before a release. In fact, the subject of automated tests has been discussed in the Unity blog so many times, one would only assume that there's a test case for this specific thing.
     
  14. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Sadly AssetBundles working in the editor is one of those things we can't have 100% test coverage, simply for the fact that AssetBundles built with the BuildPipeline API contain only Player specific data and the Editor can't read everything that is Player specific. Interestingly enough, the build pipeline rewrite (target 2018.1 release) we have experimented with the option of allowing Editor specific asset bundles to be built, it works quite well, but won't be part of the 2018.1 release as we wanted to focus on Player building bugs first.
     
  15. jasonwaltersxyz

    jasonwaltersxyz

    Joined:
    Jul 16, 2014
    Posts:
    24
    FYI today I had some time to review and created a script that references the Animation Controller and Avatar for each asset and removed the Animator. Then in my main project, I check for this script and replace with Animator. Same errors occur. My understanding now is that this AssetBundle error is related specifically to either the Animation Controller, Avatar, or both.
     
  16. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Close, it's serialized AnimationClip objects that trigger it.
     
    Deleted User and jasonwaltersxyz like this.
  17. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Do we have a confirmed 'fixed in' version for this, or is it still unfixed? - there seem to be conflicting reports here about it working or not in 2017.2 builds?

    (Definitely been seeing it all the time in 2017.1.0p4 and 2017.1.1f1, haven't tried newer versions yet)
     
  18. mbianchini

    mbianchini

    Joined:
    Aug 25, 2016
    Posts:
    5
    I have tried 2017.2 and the problem still persists... no sign of a fix for now...
     
    bluescrn likes this.
  19. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I'm getting a possibly-related issue where if I rapidly load/unload assets from bundles, things explode more spectacularly - A load of exceptions along the line of "CheckConsistency: GameObject does not reference component Transform. Fixing.", and fragments of prefab being dumped in the root of the hierarchy...

    This is when rapidly cycling through character models that are loaded async from bundles (mashing the next/previous character button as fast as possible), and it doesn't seem related to a specific bundled prefab. I'm pretty sure I've fixed the initial issue of attempting to unload a character/bundle before the async load was complete - and currently out of ideas as to what causes this. The existing spam of internal Unity assertion messages doesn't inspire confidence in the stability of the AssetBundle system, though... especially after spending a chunk of time trying to fix the reference counting in AssetBundleManager...
     
  20. jasonwaltersxyz

    jasonwaltersxyz

    Joined:
    Jul 16, 2014
    Posts:
    24
  21. jasonwaltersxyz

    jasonwaltersxyz

    Joined:
    Jul 16, 2014
    Posts:
    24
    Hello - Just want to update this thread that the issue has been resolved in the latest Unity patch 2017.2.0p2. Thank you Unity! :D
     
    bluescrn likes this.
  22. mbianchini

    mbianchini

    Joined:
    Aug 25, 2016
    Posts:
    5
    Hey @jasonrwalters thanks for the update, I'll be testing it this week!