codewriter-packages / Tri-Inspector

Free inspector attributes for Unity [Custom Editor, Custom Inspector, Inspector Attributes, Attribute Extensions]
MIT License
933 stars 43 forks source link

IndexOutOfRangeException on right click of a Flag Enum field #174

Open AntonioHR opened 3 days ago

AntonioHR commented 3 days ago

Describe the bug If I have a an enum field where the enum has the System.Flags Attribute, right clicking it results in an IndexOutOfRange Exception

Expected behavior The right click menu should appear

Code Sample

// 
  public class TriTest : MonoBehaviour {

      [Flags]
      public enum Flag {
          A = 1,
          B = 1 << 1,
          C = 1 << 2
      }

      public Flag f = Flag.B | Flag.C;
  }

Desktop: Windows 10 Unity version: 6.000.0.18f1 Tri Inspector version: 1.14.1

Here's the error log

IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEditor.Search.PropertySelectors.GetEnumValue (UnityEditor.SerializedProperty p) (at <ce6d7fd581dc45ff9d359626054f35c5>:0)
UnityEditor.Search.PropertySelectors.GetSerializedPropertyValue (UnityEditor.SerializedProperty p) (at <ce6d7fd581dc45ff9d359626054f35c5>:0)
UnityEditor.Search.SearchUtils.GetPropertyValueForQuery (UnityEditor.SerializedProperty prop) (at <ce6d7fd581dc45ff9d359626054f35c5>:0)
UnityEditor.Search.SearchUtils.FormatPropertyQuery (UnityEditor.SerializedProperty prop, System.Boolean& isAssetQuery) (at <ce6d7fd581dc45ff9d359626054f35c5>:0)
UnityEditor.Search.SearchUtils.IsPropertyValidForQuery (UnityEditor.CommandExecuteContext c) (at <ce6d7fd581dc45ff9d359626054f35c5>:0)
UnityEditor.CommandService.ExecuteCommand (System.String id, UnityEditor.CommandHint hint, System.Object[] args) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.CommandService.Execute (System.String id, UnityEditor.CommandHint hint, System.Object[] args) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.PropertyHandler.CanSearchProperty (UnityEditor.SerializedProperty property) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.PropertyHandler.AddMenuItems (UnityEditor.SerializedProperty property, UnityEditor.GenericMenu menu) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.EditorGUI.FillPropertyContextMenu (UnityEditor.SerializedProperty property, UnityEditor.SerializedProperty linkedProperty, UnityEditor.GenericMenu menu, UnityEngine.UIElements.VisualElement element) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.EditorGUI.DoPropertyContextMenu (UnityEditor.SerializedProperty property, UnityEditor.SerializedProperty linkedProperty, UnityEditor.GenericMenu menu) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.EditorGUI.EndProperty () (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.EditorGUI.DefaultPropertyField (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at <99e1d720922e4a24b7c690116a3da2c1>:0)
TriInspectorUnityInternalBridge.PropertyHandlerProxy.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at ./Library/PackageCache/com.codewriter.triinspector/Unity.InternalAPIEditorBridge.012/ScriptAttributeUtilityProxy.cs:50)
TriInspector.Elements.TriBuiltInPropertyElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Elements/TriBuiltInPropertyElement.cs:39)
TriInspector.TriElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriElement.cs:82)
TriInspector.Elements.TriPropertyElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Elements/TriPropertyElement.cs:62)
TriInspector.TriElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriElement.cs:82)
TriInspector.Elements.TriInlineGenericElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Elements/TriInlineGenericElement.cs:43)
TriInspector.TriValueDrawer`1[TValue].OnGUI (UnityEngine.Rect position, TriInspector.TriValue`1[T] propertyValue, TriInspector.TriElement next) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriValueDrawer.cs:32)
TriInspector.TriValueDrawer`1+DefaultValueDrawerElement`1[TValue,T].OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriValueDrawer.cs:57)
TriInspector.TriElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriElement.cs:94)
TriInspector.TriElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriElement.cs:82)
TriInspector.Elements.TriPropertyElement.OnGUI (UnityEngine.Rect position) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Elements/TriPropertyElement.cs:62)
TriInspector.TriPropertyTree.Draw () (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriPropertyTree.cs:95)
TriInspector.TriPropertyTreeForSerializedObject.Draw () (at ./Library/PackageCache/com.codewriter.triinspector/Editor/TriPropertyTreeForSerializedObject.cs:63)
TriInspector.Editors.TriEditorCore.OnInspectorGUI (UnityEngine.UIElements.VisualElement visualRoot) (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Editors/TriEditorCore.cs:78)
TriInspector.Editors.TriEditorCore+<>c__DisplayClass6_0.<CreateVisualElement>b__0 () (at ./Library/PackageCache/com.codewriter.triinspector/Editor/Editors/TriEditorCore.cs:117)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.IMGUIContainer.HandleEventBubbleUp (UnityEngine.UIElements.EventBase evt) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventBubbleUpInternal (UnityEngine.UIElements.EventBase evt) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.HandleEvent_BubbleUpHandleEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement element, System.Boolean disabled) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.HandleEvent_BubbleUpAllDefaultActions (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement element, System.Boolean disabled, System.Boolean isCapturingTarget) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.HandleEventAcrossPropagationPath (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target, System.Boolean isCapturingTarget) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target, System.Boolean isCapturingTarget) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.DispatchToCachedElementUnderPointerOrPanelRoot (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, System.Int32 pointerId, UnityEngine.Vector2 position) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatchUtilities.DispatchToCapturingElementOrElementUnderPointer (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, System.Int32 pointerId, UnityEngine.Vector2 position) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.MouseEventBase`1[T].Dispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <3fab0289e0f94676912019c7bb245c33>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <b8aa635a992249f2b46f45f3316b6a15>:0)
AntonioHR commented 3 days ago

Just noticed that you're supposed to use this with the TriInspector.EnumToggleButtons Attribute. That results in it not giving the error, but also not opening the context menu.

It's particularly problematic if you want to revert the enum's value to prefab default