Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

'Random' runtime error with the addressable load

Discussion in 'Addressables' started by Robdon, May 8, 2020.

  1. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Got this error logged in my online Unity Crash & Exceptions area.

    It's only happened once, out of 100s of people running the game, but I would like to know some more info around it if anyone has anything.

    Since it doesn't give me any real details, I'm guessing that it's somewhere around when I'm loading some assets like this:

    Code (CSharp):
    1. AsyncOperationHandle addHandle = Addressables.LoadAssetsAsync<Texture2D>("path-to-my-asset", op => LoadSpriteCallback(0, op));
    2.  
    3.     private void LoadSpriteCallback(int spriteNum, Texture2D op) {
    4.         spritesLoading--;
    5.         SpriteAtlas[spriteNum].mainTexture = op;
    6.         SpriteAtlas[spriteNum].mainTexture.filterMode = FilterMode.Bilinear;
    7.     }

    NullReferenceException: Object reference not set to an instance of an object

    LevelController.<Update>b__85_0 (UnityEngine.Texture2D op) (at <705b12ff155e45548ec24445ae5e4f90>:0)
    UnityEngine.ResourceManagement.ResourceManager+<>c__DisplayClass78_0`1[TObject].<ProvideResources>b__0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle x) (at <12f11939f6e542da8aab29ee21464850>:0)
    DelegateList`1[T].Invoke (T res) (at <12f11939f6e542da8aab29ee21464850>:0)
    UnityEngine.Debug:LogException(Exception)
    DelegateList`1:Invoke(AsyncOperationHandle)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update()


    I can't see how anything could be 'null' here. Or even 'what' is null.

    Is there some situation where 'op' can be null, and how would I cope with that. And also, 'why' would it be null?

    Thanks for any explanation, Rob.
     
  2. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Actually, I don't think it's that bit of code, I think it might be another bit I have in the Update(), which loads 3 textures per frame, until they are all loaded. This works fine most of the time, but I have this 1 error logged, and need to understand why.


    addHandle2[resBGAtlasSeq] = Addressables.LoadAssetsAsync<Texture2D>(atlasName, op => {
    int atlasNum = int.Parse(op.name.Split('_')[4]);
    resBGAtlas[atlasNum] = op;
    resBGAtlasLoaded++;
    });


    If I force 'op = null' as the first line of the callback section before the int atlasNum line, to force op to null, then it produces a similar error, with 'b__85_0' etc.

    So, I'm guessing op is null under some kind of instances?

    Why would it be null in the callback?

    I've tried forcing an error buy supplying an atlasName with an invalid name, but that just generates an invalid key error, not this error.
     
  3. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Ok, I've figured it out, so here is a FYI for anyone else maybe getting this problem.

    Something must have happened when they installed the game, and the asset bundle file was not there or damaged. (drive full maybe when unzipping?)

    I can simulate the error, by physically removing the bundle file in xxxxx_Data\StreamingAssets\aa\Windows\StandaloneWindows64\

    Then I get the exact same problem. op is null in the callback. I presume because it failed to read anything. Not sure how to detect that once in the callback, or by the bundle file was missing, but I guess that somewhat explains it. Maybe I can trap an exception.

    EDIT: Seems you can't use try/catch or anything to get the exception, so I guess all you can do is check op == null and just close down the app :(
     
    Last edited: May 8, 2020
  4. huangdongxc

    huangdongxc

    Joined:
    Mar 22, 2020
    Posts:
    6
    I have the same issue. Do you have a solution?
     
    User414322 likes this.