"object reference not set to an instance of an object"

Hi,
I´ve been struggling with this error for a while…
I get an “object reference not set to an instance of an object” when creating a custom class in ghpython, editing the attributes of the class via a slider, and passing the class instance to other components.
The first time it runs OK, but when changing the value of the slider the error appears, only to disappear again if clicking on recompute.

It seems OK to modify the attribute in the same component where its instance is initialised, but when the instance is passed around between other components, something goes wrong. What is it?

Can somebody please help me work around this issue?

I managed to replicate the error in a small gh file

Thanks,
nullobjecterror.gh (10.4 KB)

1 Like

@guilleramirezc the issue here is that, when passing an object from one component to another, the next component doesn’t know exactly what it’s dealing with. The only way it can figure things out is by duck typing or using some kind of introspection.
In your particular case, when the slider changes, and thus the property of the class changes, it receives a guid which needs to be coerced to a curve object. That same logic should be applied to other types. Attached the solution nullobjecterror.gh (16.6 KB)

You can avoid these unexpected behaviours by using RhinoCommon directly (i.e. circumventing unnecessary guids headaches) and not using type hints:

nullobjecterror_RhinoCommon.gh (9.0 KB)

1 Like

Thanks for the answer,
It works fine in the isolated gh file… however whenever I try this approach in the original file I get “None” returned from any of the functions of the rs.coerce family. Any hint why this might be happening?

Hi,
Perhaps I have same issue when working on color preview.
May I ask you any suggestion?

ColorPreviewError.gh (40.5 KB)