Search Unity

Question [Urgent!!!] Why AssetBundle.LoadFromFileAsync block main thread?

Discussion in 'Asset Bundles' started by aroncheng, Sep 29, 2022.

  1. aroncheng

    aroncheng

    Joined:
    Sep 29, 2022
    Posts:
    3
    I tried load an AssetBundle by using LoadFromFileAsync, but found AssetBundle.LoadFromFileAsync block the main thread. This is unexpected or expected?
    upload_2022-9-29_18-31-41.png
     
    Last edited: Sep 30, 2022
  2. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    391
    Hi, the screenshot is not enough to find the root cause. Which platform did this happen? Do you have the native callstacks of all threads when the main thread is blocking?
     
  3. aroncheng

    aroncheng

    Joined:
    Sep 29, 2022
    Posts:
    3
    Hi, Alan, how to get native callstacks of all threads?
     
  4. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    391
    It depends on the platform the game running on. Which platform is the game running?
     
  5. aroncheng

    aroncheng

    Joined:
    Sep 29, 2022
    Posts:
    3
    Android Phone
     
  6. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    391
    I just noticced that from the screenshot, it seems the main thread was not blocking forever. If it's true, maybe the native callstacks are not needed.

    I saw there are many brown blocks under Loading.ReadObjectThreaded. If you click those blocks, Unity should show some information about it, can you post them here?

    Are other threads busy when the main thread blocks? Maybe main thread is waiting for them to finish some jobs. If there are such threads, the information of them is also needed.

    P.S.
    To get native callstacks on Android, you can generate a gradle project for building development player. In Android Studio, use the project to run the built player on Android device with debugger attached. When the game blocks, you can pause the debugger, then the native callstacks will show in the Android Studio.