# Slicer crashes when attempting to retrieve camera node for non-existent 3D view

**URL:** <https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672>\
**Category:** Support\
**Created:** [May 22, 2020, 9:08pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672 "2020-05-22T21:08:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [May 22, 2020, 9:08pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672/1 "2020-05-22T21:08:09Z")

</div>

The following command entered at the Python interactor of a newly opened Slicer crashes the program and the window closes:

` camNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(slicer.app.layoutManager.threeDWidget(1).mrmlViewNode())`

This works fine if the view exists; for example

` camNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(layoutManager.threeDWidget(0).mrmlViewNode())`

does not crash Slicer and just returns the camera node for 3D View 1. I discovered this bug when I accidentally forgot to subtract 1 from the view index and requested the camera node for a view which did not exist, and lost my work in Slicer up to that point since the last time I saved.

---

<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:** [May 22, 2020, 9:22pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672/2 "2020-05-22T21:22:56Z")

</div>

Thanks for reporting this. In general, Python-wrapped C++ code is still just C++ code, which crashes if it gets invalid pointers or you try to access items out of bounds of an array, but we can harden specific calls by adding more checks and declaring item counts at the Python interface.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [May 22, 2020, 11:57pm UTC](https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672/3 "2020-05-22T23:57:26Z")

</div>

Got it. That makes sense.

---

<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:** [May 23, 2020, 5:31am UTC](https://discourse.slicer.org/t/slicer-crashes-when-attempting-to-retrieve-camera-node-for-non-existent-3d-view/11672/4 "2020-05-23T05:31:35Z")

</div>

FYI, I’ve pushed a [fix](https://github.com/Slicer/Slicer/commit/b6a93a75501393c2b033b490cc3e7bfd642d98da) for this crash.
