Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in MySerializedProperty #191

Open
Tommigun1980 opened this issue May 6, 2022 · 1 comment
Open

Crash in MySerializedProperty #191

Tommigun1980 opened this issue May 6, 2022 · 1 comment

Comments

@Tommigun1980
Copy link

Tommigun1980 commented May 6, 2022

Version: 1.7.0

NullReferenceException: Object reference not set to an instance of an object
MyBox.EditorTools.MySerializedProperty.AsStringValue (UnityEditor.SerializedProperty property) (at Library/PackageCache/com.domybest.mybox@efa34f54bc/Extensions/EditorExtensions/MySerializedProperty.cs:116)
MyBox.Internal.ConditionalFieldUtility.PropertyIsVisible (UnityEditor.SerializedProperty property, System.Boolean inverse, System.String[] compareAgainst) (at Library/PackageCache/com.domybest.mybox@efa34f54bc/Attributes/ConditionalFieldAttribute.cs:234)
MyBox.Internal.ConditionalFieldAttributeDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Library/PackageCache/com.domybest.mybox@efa34f54bc/Attributes/ConditionalFieldAttribute.cs:61)
UnityEditor.PropertyDrawer.GetPropertyHeightSafe (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:43)
UnityEditor.PropertyHandler.GetHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:301)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:248)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditorInternal.ReorderableList+Defaults.DrawElement (UnityEngine.Rect rect, UnityEditor.SerializedProperty element, System.Object listItem, System.Boolean selected, System.Boolean focused, System.Boolean draggable, System.Boolean editable) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:382)
UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect, UnityEngine.Rect visibleRect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:947)
UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:741)
UnityEditorInternal.ReorderableListWrapper.DrawChildren (UnityEngine.Rect listRect, UnityEngine.Rect headerRect, UnityEngine.Rect sizeRect, UnityEngine.Rect visibleRect, UnityEngine.EventType previousEvent) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ReorderableListWrapper.cs:200)
UnityEditorInternal.ReorderableListWrapper.Draw (UnityEngine.GUIContent label, UnityEngine.Rect r, UnityEngine.Rect visibleArea, System.String tooltip, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ReorderableListWrapper.cs:155)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:211)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditor.EditorGUI.PropertyFieldInternal (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7161)
UnityEditor.EditorGUI.PropertyField (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:8629)
MyBox.Internal.CollectionWrapperDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Library/PackageCache/com.domybest.mybox@efa34f54bc/Types/CollectionWrapper.cs:40)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:170)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:253)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditorInternal.ReorderableList+Defaults.DrawElement (UnityEngine.Rect rect, UnityEditor.SerializedProperty element, System.Object listItem, System.Boolean selected, System.Boolean focused, System.Boolean draggable, System.Boolean editable) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:382)
UnityEditorInternal.ReorderableList.DoListElements (UnityEngine.Rect listRect, UnityEngine.Rect visibleRect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:947)
UnityEditorInternal.ReorderableList.DoList (UnityEngine.Rect rect, UnityEngine.Rect visibleRect) (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:741)
UnityEditorInternal.ReorderableListWrapper.DrawChildren (UnityEngine.Rect listRect, UnityEngine.Rect headerRect, UnityEngine.Rect sizeRect, UnityEngine.Rect visibleRect, UnityEngine.EventType previousEvent) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ReorderableListWrapper.cs:200)
UnityEditorInternal.ReorderableListWrapper.Draw (UnityEngine.GUIContent label, UnityEngine.Rect r, UnityEngine.Rect visibleArea, System.String tooltip, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/ReorderableListWrapper.cs:155)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:211)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditor.EditorGUI.PropertyFieldInternal (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:7161)
UnityEditor.EditorGUI.PropertyField (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:8629)
MyBox.Internal.CollectionWrapperDrawer.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Library/PackageCache/com.domybest.mybox@efa34f54bc/Types/CollectionWrapper.cs:40)
UnityEditor.PropertyDrawer.OnGUISafe (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.Rect visibleArea) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:170)
UnityEditor.PropertyHandler.OnGUI (UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131)
UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:283)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:10841)
UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, System.Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorGUI.cs:10835)
UnityEditor.Editor.DrawPropertiesExcluding (UnityEditor.SerializedObject obj, System.String[] propertyToExclude) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:746)
MyGame.DrawRemainingProperties () (at Assets/MyGame/Editor/MyEditor.cs:61)

The code invoking the draw is:

UnityEditor.Editor.DrawPropertiesExcluding(this.serializedObject, "m_Script", nameof(someProperty), nameof(someOtherProperty));

And the object my editor is drawing is heavily using

[ConditionalField(nameof(someProperty))]

attributes.

Thank you.

@Tommigun1980
Copy link
Author

Tommigun1980 commented May 6, 2022

public static string AsStringValue(this SerializedProperty property)
calls
public static object GetValue(this SerializedProperty property)
which can return null, while
string asString = property.AsStringValue().ToUpper();
doesn't check for null, hence the crash. There may be other places also assuming GetValue() to always return a value, but I didn't check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant