Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NullReferenceException ComponentPool.cs:36 [SOLVED]
#1
Hi there.

Getting this error when trying to Build.

NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.DevTools.ComponentPool.set_Settings (FluffyUnderware.DevTools.PoolSettings value) (at Assets/Packages/DevTools/Components/ComponentPool.cs:36)
FluffyUnderware.DevTools.ComponentPool.OnValidate () (at Assets/Packages/DevTools/Components/ComponentPool.cs:97)
UnityEngine.GameObject:AddComponent()
FluffyUnderware.DevTools.PoolManager:CreateComponentPool(PoolSettings) (at Assets/Packages/DevTools/Components/PoolManager.cs:177)
FluffyUnderware.Curvy.CurvyGlobalManager:Awake() (at Assets/Packages/Curvy/Base/CurvyGlobalManager.cs:239)
UnityEngine.GameObject:AddComponent()
FluffyUnderware.DevTools.DTSingleton`1:get_Instance() (at Assets/Packages/DevTools/Components/DTSingleton.cs:57)
FluffyUnderware.Curvy.CurvySpline:Awake() (at Assets/Packages/Curvy/Base/CurvySpline.cs:575)
UnityEngine.GUIUtilityTonguerocessEvent(Int32, IntPtr)

I've tried deleting and re-importing from Packages folder.


Thanks,
Rob
Reply
#2
I found the cause of the issue... it may be something that's common knowledge but took me a while to figure out.

A scene in my project has a sub-scene using some curvy splines and so it has a _CurvyGlobal. The main scene also have splines and it's own _CurvyGlobal.
Removing these from the subscene has fixed the errors.
Reply
#3
Thanks for the heads up, this would have tripped me up later in dev for sure!
Reply
#4
We ran into this issue exclusively when we were on the Android platform in the editor. In our case we couldn't just remove the Curvy Global instance (it kept coming back).

But looking into it, I think we've figured out where this bug comes from. In 2017.2, Unity changed it so that

Quote:MonoBehaviour.OnValidate is now called when MonoBehaviour is added to a GameObject in the Editor

From: https://docs.unity3d.com/2017.2/Documentation/Manual/UpgradeGuide20172.html

The setter in ComponentPool.cs assumes the value you pass in is not null

Code:
public PoolSettings Settings
       {
           get { return m_Settings; }
           set
           {
               Debug.Log(this.gameObject.scene.name);
               if (m_Settings != value)
                   m_Settings = value;
               m_Settings.OnValidate();
           }
       }

However, it also has a OnValidate method

Code:
       void OnValidate()
       {
           Settings = m_Settings;
       }

And this component is created dynamically in PoolManager.CreateComponentPool

Code:
if (!Pools.TryGetValue(typeof(T).AssemblyQualifiedName, out res))
           {
               res = gameObject.AddComponent<ComponentPool>();
               ((ComponentPool)res).Initialize(typeof(T),s);
               Pools.Add(res.Identifier, res);
           }

And in this code, the component is created in AddComponent with a null value for m_Settings, because the settings are only passed in through the subsequent Initialize call. However, in 2017.2, the AddComponent will call OnValidate, which will set the Settings property to the null value, which has no null check.

So we fixed it by adding a null check in the setter:

Code:
public PoolSettings Settings
       {
           get { return m_Settings; }
           set
           {
               Debug.Log(this.gameObject.scene.name);
               if (m_Settings != value)
                   m_Settings = value;
               if(m_Settings != null)
               {
                   m_Settings.OnValidate();
               }
           }
Reply
#5
Great work, @Lingumi ! I think I'll keep that in mind in the future.
Reply
#6
Wow, thanks @Lingumi -- I came to the forum with this very same bug. Thanks for sharing!
Reply
#7
Hi,
Good job @Lingumi. I hope that I have read your post before fixing this issue on my own, it would have avoided me some unnecessary investigations.
The fix for this issue will be available in 2.2.0
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Assembly Definitions (Solved) lacota 3 6 06-01-2023, 11:04 AM
Last Post: _Aka_
  GetComponent<SplineController>() doesn't work? [SOLVED] ionside 0 2,244 07-10-2016, 02:37 AM
Last Post: ionside
  [Solved] SplineController skips on CurvySpline.ControlPoints[0].Delete() cpoll 6 10,614 02-15-2016, 04:56 PM
Last Post: cpoll
  [SOLVED] Additional fields on a Connection Trainzland 6 9,947 01-27-2016, 07:18 PM
Last Post: Jake

Forum Jump: