# Issue with HardenTransform

**URL:** <https://discourse.slicer.org/t/issue-with-hardentransform/29240>\
**Category:** Support\
**Created:** [May 2, 2023, 9:54am UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240 "2023-05-02T09:54:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gholl](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gholl](https://discourse.slicer.org/u/Gholl)\
**Post date:** [May 2, 2023, 9:54am UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240/1 "2023-05-02T09:54:42Z")

</div>

I’m writing a script and trying to apply HardenTransform on a segmentation node as follows.

```auto
seg_node.SetAndObserveTransformNodeID(transformNodeID.GetID())
seg_node.HardenTransform()

```

This works fine for most samples but sometimes the script crashes (triggered at HardenTransform) and yields the following error:

```auto
Unable to allocate 227735193073740 elements of size 4 bytes. 

"Slicer has caught an application error, please save your work and restart.\n\nThe application has run out of memory. Increasing swap size in system settings or adding more RAM may fix this issue.\n\nIf you have a repeatable sequence of steps that causes this message, please report the issue following instructions available at https://slicer.org\n\n\nThe message detail is:\n\nException thrown in event: std::bad_alloc"

```

transformNode has `slizeSizeMM = [float(15.0), float(15.0)]` but when changing to e.g. `slizeSizeMM = [float(13.0), float(13.0)]` the script works fine on the samples triggering this error.

From what I’ve read earlier there are some issues related to HardenTransform on large segmentations (see [Harden transform on large segmentation hangs 3D Slicer](https://discourse.slicer.org/t/harden-transform-on-large-segmentation-hangs-3d-slicer/5643)). In my case, the underlying segmentations seem to be “longer” than normal relative to other samples.

Is there any effective more general solution to this issue?

OS: Ubuntu 20.04  
Slicer3D version: 5.2.2

Thanks!

---

<div class="post-metadata">

**Author:** ![Gholl](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gholl](https://discourse.slicer.org/u/Gholl)\
**Post date:** [May 2, 2023, 1:02pm UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240/2 "2023-05-02T13:02:44Z")

</div>

Typo, should be:

```auto
seg_node.SetAndObserveTransformNodeID(transformNode.GetID())
seg_node.HardenTransform()

```

---

<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 2, 2023, 7:51pm UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240/3 "2023-05-02T19:51:21Z")

</div>

If you specify a transform that would make the resulting segmentation so big that it cannot fit into memory then the operation is expected to fail. We can tell if it is a software issue or just incorrect input if you provide a sample data set and processing script that reproduces the problem.

---

<div class="post-metadata">

**Author:** ![Gholl](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gholl](https://discourse.slicer.org/u/Gholl)\
**Post date:** [May 3, 2023, 10:38am UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240/4 "2023-05-03T10:38:34Z")

</div>

Ok, that makes sense. Unfortunately, I cannot provide you with sample data. Is there any way to catch this error instead of having the script crash?

Thanks!

---

<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 3, 2023, 11:55am UTC](https://discourse.slicer.org/t/issue-with-hardentransform/29240/5 "2023-05-03T11:55:00Z")

</div>

You can try to reproduce it with data sets in Slicer"s Sample Data module or other public data sets.
