Search Unity

[CASE 1103042] FindAssetEntry constant NullReference

Discussion in 'Addressables' started by aurelien-morel-ubiant, Nov 19, 2018.

  1. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Hello guys,
    I start to use the new Addressables system to manage our future AB logic.
    My project's using Unity 2018.3b8 and Addressables 0.4.8-preview.

    And for no reason in my project I have now an issue each time I click on an element in the project window Addressable asset or not, so bascially I can't click on anything at all without this issue and a broken inspector display (due to null reference):

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.AddressableAssets.AddressableAssetSettings.FindAssetEntry (System.String guid) (at Library/PackageCache/com.unity.addressables@0.4.8-preview/Editor/Settings/AddressableAssetSettings.cs:885)
    3. UnityEditor.AddressableAssets.AddressableAssetInspectorGUI.OnPostHeaderGUI (UnityEditor.Editor editor) (at Library/PackageCache/com.unity.addressables@0.4.8-preview/Editor/GUI/AssetInspectorGUI.cs:67)
    4. UnityEditor.Editor.DrawHeader () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:697)
    5. UnityEditor.InspectorWindow.DrawEditorLargeHeader (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, UnityEditor.Editor editor, System.Boolean& wasVisible) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1519)
    6. UnityEditor.InspectorWindow.DrawEditorHeader (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, UnityEditor.Editor editor, UnityEngine.Object target, System.Boolean& wasVisible) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1488)
    7. UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex, System.Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1424)
    8. UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1300)
    9. UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:643)
    10. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    11. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    12. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    13. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
    14. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
    15. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
    16. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310)
    17. UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:363)
    18. UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:322)
    19. UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244)
    20. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    21.  
    And the inspector image
    upload_2018-11-19_11-13-32.png

    I tried to create a sample project with my addressables assets from this broken project but no errors are triggered.

    Edit : I tried to delete "Library", this changed nothing.
    Edit 2 : I deleted all addressable package & files and problem is solved. (obviously)
    Edit 3 : I will install the package again and check if somthing in particular trigger this.
    Edit 4 : Resintall package doesn't trigger the issue but my Addressable asset yes... So something broken in them trigger a constant NullReferences on all element in my project (but not in my sample project with the same elements)
     
    Last edited: Nov 19, 2018
  2. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    @unity_bill is it something known / fixed or that will be fixed ?
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    We've tried to repro your issue and can't so far. Can you create a bug through Unity's bug report mechanism (and tell me the case # here)? If you could attach a sample project to that bug, that would really help us get to the bottom of this.

    Thanks,
    Bill
     
  4. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    I will try today to recreate this one. Since monday, I cleared my impacted project and removed Addressables.
    In a sample project the issue doesn't happen.

    So I will install again the "Addressable" package and backported again my corrupted package in my project.
    I can upload our project but it will be something like many gigs.
     
  5. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    @unity_bill I reproduced it and I submit a project sample with the bug and a description of what happened.
    It's not the same step than the one I mentionned above (I'm pretty sure) but the result is the same NullReferenceException.

    ===
    For the step do reproduce it :
    Create an empty project
    Import in this project the following 2 existing Addressable folders from another project where you setup some elements :
    AddressableAssetsData
    AssetBundleResources

    Then go in Window/Asset Management/Addressable Assets.
    It will ask you if you wanna Create or Import.
    Click on Create and it will triggered the issue (at least here it does)
    ===

    My case is 1103042.

    From what I can see in your code base there is a lot of foreach wihtout NullReference protection. It's maybe intended cause it mustn't happen but the fact is currently it does :/

    Some case like this one :
    AddressableAssetSettings, line 885 currently you have :

    Code (CSharp):
    1.  foreach (var g in groups)
    2. {
    3.        var e = g.GetAssetEntry(guid);
    4.        if (e != null)
    5.             return e;
    6. }
    but for me it will be safer to do :

    Code (CSharp):
    1.  foreach (var g in groups)
    2. {
    3.     if( g != null )
    4.    {              
    5.         var e = g.GetAssetEntry(guid);
    6.         if (e != null)
    7.            return e;
    8.     }
    9. }
    At least this solve my current case report right above.

    I triggered an issue in a method named "GatherAllAssets" from AddressableAssetGroup cause the same king of thing happens :

    Code (CSharp):
    1. foreach (var e in entries)
    2.       e.GatherAllAssets(results, includeSelf, recurseAll);
    replaced by this :

    Code (CSharp):
    1. foreach (var e in entries)
    2.      if( e != null )
    3.           e.GatherAllAssets(results, includeSelf, recurseAll);
    I know what I just did is quite dirty, it was just a fast fix in my current case.
    The proper way would be to remove the entry in the "Addressable Assets" window when a group is deleted from the hierarchy, in this way you won't have something like this for example :

    upload_2018-11-22_11-24-34.png
     
    Last edited: Nov 22, 2018
  6. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    To make it simple I drop here the archive of the Editor folder from your "com.unity.addressables@0.4.8-preview" that I customized to integrate all my fixes concerning the addressableAssetGroup reference broken during my Addressable Asset window usage and during the build pipeline triggered when you pressed play.

    Basically there is probably too many "!= null" added but some are added to manage the current scriptableObject "AddressableAssetSettings.asset" corrupted with some "None" references. All those added in the Build folder from your package are probably irrelevant cause when we reached this state, the asset must be cleaned (which is not the case in my current project.) I have to add a clean up from this asset in case I found "None" references.

    My dirtiest is probably the this != null in the AddressableAssetGroup.SetDirty. Sorry for this one :p

    Sorry for this HUGE SPAM.:/
     

    Attached Files:

  7. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for all the info and the sample. I've made a note to look at your fixes and integrate what we can.

    This is super helpful
     
  8. ANicholas

    ANicholas

    Joined:
    Nov 20, 2013
    Posts:
    3
    Hey Bill, this doesn't seem to be fixed still in version 1.1.10 of the package.



    I've attached the full stacktrace for each exception.

    I'm just trying to open the Addressables UI panel and this is what I'm seeing. Was working fine yesterday, but I've been doing a lot of work recently creating new groups, assigning assets to them, and providing new addresses for each. I did a bit of re-org which required me to delete some groups, perhaps these are the null values? I'm not entirely sure at the moment.

    EDIT: Digging a bit deeper, it does indeed seem to be a null group somewhere.

    I added the NULL check in the section Aurelien had:
    Code (CSharp):
    1. public AddressableAssetEntry FindAssetEntry(string guid)
    2.         {
    3.             foreach (var g in groups)
    4.             {
    5.                 if( g != null )
    6.                 {
    7.                     var e = g.GetAssetEntry( guid );
    8.                     if( e != null )
    9.                         return e;
    10.                 }
    11.             }
    12.             return null;
    13.         }
    Now I'm getting a NULL exception at this constructor, particularly where the AddressableAssetGroup g is accessed in the base constructor call:

    Code (CSharp):
    1. public AssetEntryTreeViewItem(AddressableAssetGroup g, int d) : base(g.Guid.GetHashCode(), d, g.Name)
    2.         {
    3.             entry = null;
    4.             group = g;
    5.             assetIcon = null;
    6.             isRenaming = false;
    7.         }
    The only place that constructor seems to be called is:

    Code (CSharp):
    1. void AddGroupChildrenBuild(AddressableAssetGroup group, TreeViewItem root)
    2.         {
    3.             var groupItem = new AssetEntryTreeViewItem(group, 0);
    4.             root.AddChild(groupItem);
    5.             if (group.entries.Count > 0)
    6.             {
    7.  
    8.                 foreach (var entry in group.entries)
    9.                 {
    10.                     AddAndRecurseEntriesBuild(entry, groupItem, 1);
    11.                 }
    12.             }
    13.         }
     

    Attached Files:

    Last edited: May 15, 2020
  9. ANicholas

    ANicholas

    Joined:
    Nov 20, 2013
    Posts:
    3
    I'm also now seeing stack overflow warnings and my addressables no longer display in the UI...



    Any idea why it may be trying to load the settings multiple times?