Why does this trivial call result in a crash?

I am trying to create a module in C++ and am stumbling on a crash on line 4 below :

vtkMRMLNode * fiducialNode = d->inputFiducialSelector->currentNode();
vtkMRMLMarkupsFiducialNode * fiducialNodeReal = vtkMRMLMarkupsFiducialNode::SafeDownCast(fiducialNode);
std::cout << fiducialNodeReal->GetClassName() << std::endl; // OK
std::cout << fiducialNodeReal->GetNumberOfControlPoints() << std::endl; // Crash

The module is created using the extension wizard. The code is executed when a button is clicked. Debugging does not help, no thread is available on crash (Slicer and the module are compiled with RelWithDebInfo).

This very primitive sample illustrates the issue.

I wish to avoid a fallback on Python, and would appreciate any comment to help resolve this.

Thank you.

It seems that fiducialNodeReal is a null pointer. You can confirm this by adding a null-pointer check or building Slicer in debug mode.

In RelWithDebInfo mode, unnecessary temporary variables are optimized out, so you won’t be able to step through the source code lines that create them.

Thanks for replying.

While comparing with other C++ modules, I ended up with this efficient patch.

Should the extension wizard template for a loadable module be updated?