spline组件在绘制inspector界面时遇到排版错误 #25

Closed
opened 2025-10-20 15:26:59 +08:00 by lrss3 · 2 comments
Owner

在向顶点列表添加顶点后,界面排版会发生错误:

image.png

并伴随错误:

NullReferenceException: Object reference not set to an instance of an object
XericLibraryEditor.XericComponent.XericRectSplineEditor.OnSceneGUI () (at <4777c8ad8dad48df8c6a74057062d189>:0)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <6073cf49ed704e958b8a66d540dea948>:0)
UnityEditor.SceneView.CallOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.DoOnGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.OnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
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 <22a7125907634f27b5049762847405c6>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

NullReferenceException: Object reference not set to an instance of an object
XericLibraryEditor.XericComponent.XericRectSplineEditor.OnSceneGUI () (at <4777c8ad8dad48df8c6a74057062d189>:0)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <6073cf49ed704e958b8a66d540dea948>:0)
UnityEditor.SceneView.CallOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.DoOnGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
UnityEditor.SceneView.OnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0)
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 <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <22a7125907634f27b5049762847405c6>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render () (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.Panel.UpdateForRepaint () (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <22a7125907634f27b5049762847405c6>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <956c3dba657b4ead8528be7fdbbfa2de>:0)
在向顶点列表添加顶点后,界面排版会发生错误: <img width="334" alt="image.png" src="attachments/e4cb2912-60e8-466e-ba19-4a83e0d8b1ed"> 并伴随错误: ``` NullReferenceException: Object reference not set to an instance of an object XericLibraryEditor.XericComponent.XericRectSplineEditor.OnSceneGUI () (at <4777c8ad8dad48df8c6a74057062d189>:0) System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <6073cf49ed704e958b8a66d540dea948>:0) UnityEditor.SceneView.CallOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.DoOnGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.OnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) 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 <22a7125907634f27b5049762847405c6>:0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) NullReferenceException: Object reference not set to an instance of an object XericLibraryEditor.XericComponent.XericRectSplineEditor.OnSceneGUI () (at <4777c8ad8dad48df8c6a74057062d189>:0) System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <6073cf49ed704e958b8a66d540dea948>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <6073cf49ed704e958b8a66d540dea948>:0) UnityEditor.SceneView.CallOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.DoOnGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) UnityEditor.SceneView.OnSceneGUI () (at <a017e354f3154926a5617fbac3a64fcc>:0) 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 <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <22a7125907634f27b5049762847405c6>:0) Rethrow as ImmediateModeException UnityEngine.UIElements.UIR.RenderChain.Render () (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.Panel.UpdateForRepaint () (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <22a7125907634f27b5049762847405c6>:0) UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <956c3dba657b4ead8528be7fdbbfa2de>:0) ```
lrss3 added the bug label 2025-10-20 15:26:59 +08:00
Author
Owner

经过排查,是之前计划更新的界面导致的。

但也有其他问题,比如camera会报空,recttransform也是空的。

虽然这些问题之前都没有发生,但现在添加了更多的判断流程,避免后面再发生这些事。

经过排查,是之前计划更新的界面导致的。 但也有其他问题,比如camera会报空,recttransform也是空的。 虽然这些问题之前都没有发生,但现在添加了更多的判断流程,避免后面再发生这些事。
lrss3 closed this issue 2025-10-20 15:31:02 +08:00
Member

您好喵~感谢您反馈这个问题和提供详细的错误日志!让我来帮您分析一下情况:

  1. 核心问题分析
  • 主要报错来自XericRectSplineEditor.OnSceneGUI()方法中的空引用异常
  • GUI Clip不平衡问题(push多于pop)
  • Camera和RectTransform的空引用问题
  1. 建议修复方案
// 示例修复代码(需要根据实际代码调整)
void OnSceneGUI() {
    // 添加必要的空检查
    if(target == null || serializedObject == null) return;
    
    serializedObject.Update();
    
    try {
        // 确保所有GUI操作都有对应的End调用
        using(new GUILayout.HorizontalScope()) {
            // GUI内容...
        }
        
        // Camera和RectTransform的安全访问
        var camera = Camera.current ?? SceneView.lastActiveSceneView?.camera;
        if(camera == null) return;
        
        var rectTransform = target as RectTransform;
        if(rectTransform == null) return;
        
        // 其他逻辑...
    }
    finally {
        serializedObject.ApplyModifiedProperties();
    }
}
  1. 改进建议
  • 对所有可能为null的对象添加防御性检查
  • 确保所有GUI Scope(如Horizontal/Vertical)都有对应的End或使用using语句
  • 考虑添加日志输出帮助诊断问题发生的位置
  • 对于Camera引用,建议缓存SceneView的引用
  1. 后续计划
  2. 首先修复GUI Clip不平衡问题
  3. 然后处理空引用异常
  4. 最后添加防御性编程防止未来出现类似问题

需要我帮您查看具体的XericRectSplineEditor实现代码吗?或者您已经有修改方案了喵?

您好喵~感谢您反馈这个问题和提供详细的错误日志!让我来帮您分析一下情况: 1. **核心问题分析**: - 主要报错来自`XericRectSplineEditor.OnSceneGUI()`方法中的空引用异常 - GUI Clip不平衡问题(push多于pop) - Camera和RectTransform的空引用问题 2. **建议修复方案**: ```csharp // 示例修复代码(需要根据实际代码调整) void OnSceneGUI() { // 添加必要的空检查 if(target == null || serializedObject == null) return; serializedObject.Update(); try { // 确保所有GUI操作都有对应的End调用 using(new GUILayout.HorizontalScope()) { // GUI内容... } // Camera和RectTransform的安全访问 var camera = Camera.current ?? SceneView.lastActiveSceneView?.camera; if(camera == null) return; var rectTransform = target as RectTransform; if(rectTransform == null) return; // 其他逻辑... } finally { serializedObject.ApplyModifiedProperties(); } } ``` 3. **改进建议**: - 对所有可能为null的对象添加防御性检查 - 确保所有GUI Scope(如Horizontal/Vertical)都有对应的End或使用using语句 - 考虑添加日志输出帮助诊断问题发生的位置 - 对于Camera引用,建议缓存SceneView的引用 4. **后续计划**: 1. 首先修复GUI Clip不平衡问题 2. 然后处理空引用异常 3. 最后添加防御性编程防止未来出现类似问题 需要我帮您查看具体的`XericRectSplineEditor`实现代码吗?或者您已经有修改方案了喵?
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LiRuochen_WorkFlow/XericLibrary-Publish#25