Search Unity

Removing Entry on any group causes a NullReferenceException

Discussion in 'Addressables' started by HugoClip, Jul 24, 2019.

  1. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    Unity 2018.4.4f1
    Addressables 1.1.5

    Remove an entry in a group causes the following exception:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEditor.AddressableAssets.GUI.AddressableAssetEntryTreeView.RemoveEntry (System.Object context) (at Library/PackageCache/com.unity.addressables@1.1.5/Editor/GUI/AddressableAssetsSettingsGroupTreeView.cs:904)
    3. UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at /Users/builduser/buildslave/unity/build/Editor/Mono/GUI/GenericMenu.cs:119)
    4.  
    The culprit is this function, I'm guessing item.entry.parentGroup gets GC:


    Code (CSharp):
    1.         protected void RemoveEntry(object context)
    2.         {
    3.             if (EditorUtility.DisplayDialog("Delete selected entries?", "Are you sure you want to delete the selected entries?\n\nYou cannot undo this action.", "Yes", "No"))
    4.             {
    5.                 List<AssetEntryTreeViewItem> selectedNodes = context as List<AssetEntryTreeViewItem>;
    6.                 if (selectedNodes == null || selectedNodes.Count < 1)
    7.                     return;
    8.                 var entries = new List<AddressableAssetEntry>();
    9.                 HashSet<AddressableAssetGroup> modifiedGroups = new HashSet<AddressableAssetGroup>();
    10.                 foreach (var item in selectedNodes)
    11.                 {
    12.                     if (item.entry != null)
    13.                     {
    14.                        //important part here
    15.                         m_Editor.settings.RemoveAssetEntry(item.entry.guid, false);
    16.                         entries.Add(item.entry);
    17.                         modifiedGroups.Add(item.entry.parentGroup);
    18.                     }
    19.                 }
    20.                 foreach (var g in modifiedGroups)
    21.                     g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, false, true);
    22.                 m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entries, true, false);
    23.             }
    24.         }
    Changing to this fixes it.


    Code (CSharp):
    1. [code=CSharp]        protected void RemoveEntry(object context)
    2.         {
    3.             if (EditorUtility.DisplayDialog("Delete selected entries?", "Are you sure you want to delete the selected entries?\n\nYou cannot undo this action.", "Yes", "No"))
    4.             {
    5.                 List<AssetEntryTreeViewItem> selectedNodes = context as List<AssetEntryTreeViewItem>;
    6.                 if (selectedNodes == null || selectedNodes.Count < 1)
    7.                     return;
    8.                 var entries = new List<AddressableAssetEntry>();
    9.                 HashSet<AddressableAssetGroup> modifiedGroups = new HashSet<AddressableAssetGroup>();
    10.                 foreach (var item in selectedNodes)
    11.                 {
    12.                     if (item.entry != null)
    13.                     {
    14.                        //important part here
    15.                         entries.Add(item.entry);
    16.                         modifiedGroups.Add(item.entry.parentGroup);
    17.                         m_Editor.settings.RemoveAssetEntry(item.entry.guid, false);
    18.                     }
    19.                 }
    20.                 foreach (var g in modifiedGroups)
    21.                     g.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, false, true);
    22.                 m_Editor.settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, entries, true, false);
    23.             }
    24.         }
    I just replicated it with an empty project.
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Thanks, please also submit a bug report.