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

Constant null reference exceptions in editor #136

Open
mistertoenails opened this issue May 5, 2023 · 5 comments
Open

Constant null reference exceptions in editor #136

mistertoenails opened this issue May 5, 2023 · 5 comments

Comments

@mistertoenails
Copy link

As soon as I add a path creator script, I get the following error over and over again until I remove the component:

NullReferenceException: Object reference not set to an instance of an object
PathCreation.BezierPath.GetPoint (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:131)
@CaroRed
Copy link

CaroRed commented Jul 21, 2023

Hello, same here I just add the script to a GameObject and appears errors on the console.

NullReferenceException: Object reference not set to an instance of an object
PathCreation.BezierPath.CalculateBoundsWithTransform (UnityEngine.Transform transform) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:494)
PathCreationEditor.PathEditor.DrawBezierPathSceneEditor () (at Assets/PathCreator/Core/Editor/PathEditor.cs:519)
PathCreationEditor.PathEditor.OnSceneGUI () (at Assets/PathCreator/Core/Editor/PathEditor.cs:337)
(wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,UnityEditor.Editor)

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

And more, like 7 errors.

I'm using Unity 2022.1.12f1

Thanks!

@ViZAlice
Copy link

same. And I need to start game , then there is no more null reference. But still can't see any curve in scence , then i need to click the ResetPath. There is a curve now. But I don't think it's a permanent solution

@KiritoWangCA
Copy link

Yes, this problem seems to happen in unity 2022, there is no such problem in 2021.

@prostolyubo
Copy link

Yes, this problem seems to happen in unity 2022, there is no such problem in 2021.

I have this problem in Unity 2021.3.25f1

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <8dda741d2f7042a7a836980a676458c6>:0)
PathCreation.BezierPath.GetPoint (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:131)
PathCreation.BezierPath.get_Item (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:125)
PathCreation.Utility.VertexPathUtility.SplitBezierPathByAngleError (PathCreation.BezierPath bezierPath, System.Single maxAngleError, System.Single minVertexDst, System.Single accuracy) (at Assets/PathCreator/Core/Runtime/Utility/VertexPathUtility.cs:13)
PathCreation.VertexPath..ctor (PathCreation.BezierPath bezierPath, UnityEngine.Transform transform, System.Single maxAngleError, System.Single minVertexDst) (at Assets/PathCreator/Core/Runtime/Objects/VertexPath.cs:49)
PathCreation.PathCreatorData.GetVertexPath (UnityEngine.Transform transform) (at Assets/PathCreator/Core/Runtime/Objects/PathCreatorData.cs:103)
PathCreation.PathCreator.get_path () (at Assets/PathCreator/Core/Runtime/Objects/PathCreator.cs:25)
PathCreation.PathCreator.OnDrawGizmos () (at Assets/PathCreator/Core/Runtime/Objects/PathCreator.cs:82)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)

@pazzaar
Copy link

pazzaar commented Sep 30, 2023

Unsure why this is specifically happening in 2022, but it looks like it's trying to initialize the _bezierPath variable in PathCreatorData.cs because its marked with the SerializeField attribute. When you add the component to your scene, _bezierPath is then set to not null and the null check in Initialize on line 46 in PathCreatorData.cs doesn't pass and the Bezier doesn't get created correctly.

Removing [SerializeField] on line 12 (the one above _bezierPath) in PathCreatorData.cs fixes this for me. Probably not the best fix in the world but its doing the trick for me at the moment.

    [System.Serializable]
    public class PathCreatorData {
        public event System.Action bezierOrVertexPathModified;
        public event System.Action bezierCreated;

        [SerializeField]  //<-- Remove this attribute
        BezierPath _bezierPath;
        VertexPath _vertexPath;

        [SerializeField]
        bool vertexPathUpToDate;
        //Rest of the code
    }

EDIT nvm #135 seems like a more reasonable solution. I would do that instead

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

6 participants