# Dwirecon Segmentation fault: Invalid memory access

**URL:** <https://community.mrtrix.org/t/dwirecon-segmentation-fault-invalid-memory-access/4244>\
**Category:** Uncategorized\
**Created:** [October 30, 2020, 12:41pm UTC](https://community.mrtrix.org/t/dwirecon-segmentation-fault-invalid-memory-access/4244 "2020-10-30T12:41:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Hansen](https://community.mrtrix.org/user_avatar/community.mrtrix.org/colin_hansen/32/3004_2.png) [@Colin\_Hansen](https://community.mrtrix.org/u/Colin_Hansen)\
**Post date:** [October 30, 2020, 12:41pm UTC](https://community.mrtrix.org/t/dwirecon-segmentation-fault-invalid-memory-access/4244/1 "2020-10-30T12:41:38Z")

</div>

Hello,  
I’m trying to use the shard-recon package for my DWI data. The process seems to finish running, but fails while trying to save the output. This is the relevant output with the debug flag:

…  
dwirecon: [INFO] Transpose projection - regularisers  
dwirecon: CG: #iterations: 4  
dwirecon: CG: estimated error: 3.26593581e-05  
dwirecon: [INFO] creating image “recon.mif”…  
dwirecon: [DEBUG] sanitising image information…  
dwirecon: [DEBUG] creating empty file “recon.mif”  
dwirecon: [INFO] file “recon.mif” already exists - removing  
dwirecon: [DEBUG] resizing file “recon.mif” to 99536900  
dwirecon: [DEBUG] sanitising image information…  
dwirecon: [INFO] image “recon.mif” created with dimensions 96x96x60x3x15, voxel spacing 2.3958300000000001x2.3958300000000001x2.3999999999999999x1xnan, datatype Float32LE  
dwirecon: [DEBUG] memory-mapping file “recon.mif”…  
dwirecon: [DEBUG] “recon.mif” appears to reside on a networked filesystem - using delayed write-back  
dwirecon: [DEBUG] file “recon.mif” held in RAM at 0x7fd02f27a010, size 99532800  
dwirecon: [DEBUG] image “recon.mif” loaded  
dwirecon: [DEBUG] image “recon.mif” initialised with strides = [45 4320 414720 15 1], start = 0, using direct IO  
terminate called after throwing an instance of ‘std::bad\_alloc’  
what(): std::bad\_alloc

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [November 10, 2020, 2:26am UTC](https://community.mrtrix.org/t/dwirecon-segmentation-fault-invalid-memory-access/4244/2 "2020-11-10T02:26:29Z")

</div>

Welcome Colin!

Given that the SHARD recon is an external project and not yet a part of the _MRtrix3_ software, it may be more appropriate to post over on the relevant [issue list](https://github.com/dchristiaens/shard-recon/issues), as there’s a chance that it may be a problem specific to the contents of that project and not of the _MRtrix3_ back-end against which it is built.

Nevertheless, a couple of suggestions:

1. Run `top` in another terminal and monitor the RAM usage. If it approaches 100% prior to termination of the command, then your system does not possess sufficient RAM to process your data.

2. A `std::bad_alloc` can unfortunately mask the source of the problem if it is not as simple as insufficient RAM. The instructions [here](https://community.mrtrix.org/t/advanced-debugging-of-mrtrix3-binaries/2555) explain how to better isolate the source of the problem; however the runtime would be exceptionally long if running in debug mode.

3. This:

Cheers  
Rob

---

<div class="post-metadata">

**Author:** ![dchristiaens](https://community.mrtrix.org/user_avatar/community.mrtrix.org/dchristiaens/32/2347_2.png) [@dchristiaens](https://community.mrtrix.org/u/dchristiaens)\
**Post date:** [November 10, 2020, 3:08pm UTC](https://community.mrtrix.org/t/dwirecon-segmentation-fault-invalid-memory-access/4244/3 "2020-11-10T15:08:10Z")

</div>

Hi - sorry for being late to reply. Colin had already nudged me offline and we managed to identify the source of this segfault as a bug in `dwirecon` that arises only when no basis functions (option `-rf`) are provided. This issue does not occur when run through the main command `dwimotioncorrect`. I will push a fix to GitHub that sets the defaults correctly or throws a warning.
