How to get a scene reliably and why is it null?

Hello,

I am stumbling on getting a scene node in most functions of a class while it is not null elsewhere in the same class (1, 2, 3).

In the constructor of the referenced class for example, it is always null, and in many functions also. The node is well registered.

Can a core developer provide a hint to resolve this?

Thank you.

Precisions:

It 's on Linux and Slicer is built at de382bd89.

Have you tried this->Scene?
Had your node already been added to the scene?

There’s a distinction between registering the node type so that the scene knows how to operate on it, and adding an instance of the node type to the scene. The node class needs to know what scene it is in so it can do things like creating the default display and storage nodes, adding them to the scene, and referencing their IDs.

Some node methods, like UpdateNumberOfControlPoints you referenced, really should include a check for a null scene pointer. Probably it’s not been added since that operation is unlikely to be called unless the node is already in use in a valid scene.

Does that address your question @chir.set ?

I have reworked parts of the project and things are more predictable now. Namely with this commit that does nothing special now in a constructor, apart from an elementary assignment . A major cause of trouble was a cout statement in the constructor (the cout seemed elementary too :smile: ). This seemed very disturbing to whatever underneath, even the markups raw pointer was changing randomly. Once removed, things calmed down.

Thank you for having considered.