# Why does this trivial call result in a crash?

**URL:** https://discourse.slicer.org/t/why-does-this-trivial-call-result-in-a-crash/24742
**Category:** Development
**Created:** [August 13, 2022, 8:24pm UTC](https://discourse.slicer.org/t/why-does-this-trivial-call-result-in-a-crash/24742 "2022-08-13T20:24:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)
#### Post date: [August 13, 2022, 8:24pm UTC](https://discourse.slicer.org/t/why-does-this-trivial-call-result-in-a-crash/24742/1 "2022-08-13T20:24:29Z")

</div>

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

```auto
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](https://github.com/chir-set/Tinkering/blob/9cf3c92bd44405272753796bd63c25dae0a17ee0/Test0/qSlicerTest0ModuleWidget.cxx#L77) illustrates the issue.

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

Thank you.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 13, 2022, 9:01pm UTC](https://discourse.slicer.org/t/why-does-this-trivial-call-result-in-a-crash/24742/2 "2022-08-13T21:01:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)
#### Post date: [August 14, 2022, 8:39am UTC](https://discourse.slicer.org/t/why-does-this-trivial-call-result-in-a-crash/24742/3 "2022-08-14T08:39:59Z")

</div>

Thanks for replying.

While comparing with other C++ modules, I ended up with [this](https://github.com/chir-set/Tinkering/commit/cb9867a47f40c857b53facf4fc79f72103cce872) efficient patch.

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