diff --git a/src/dwi/tractography/SIFT2/tckfactor.cpp b/src/dwi/tractography/SIFT2/tckfactor.cpp index 0375cb5cf2..d28bf78309 100644 --- a/src/dwi/tractography/SIFT2/tckfactor.cpp +++ b/src/dwi/tractography/SIFT2/tckfactor.cpp @@ -344,19 +344,22 @@ namespace MR { { if (size_t(coefficients.size()) != contributions.size()) throw Exception ("Cannot output weighting factors if they have not first been estimated!"); + decltype(coefficients) weights; try { - decltype(coefficients) weights (coefficients.size()); - for (SIFT::track_t i = 0; i != num_tracks(); ++i) - weights[i] = (coefficients[i] == min_coeff || !std::isfinite(coefficients[i])) ? - 0.0 : - std::exp (coefficients[i]); - save_vector (weights, path); + weights.resize (coefficients.size()); } catch (...) { WARN ("Unable to assign memory for output factor file: \"" + Path::basename(path) + "\" not created"); + return; } + for (SIFT::track_t i = 0; i != num_tracks(); ++i) + weights[i] = (coefficients[i] == min_coeff || !std::isfinite(coefficients[i])) ? + 0.0 : + std::exp (coefficients[i]); + save_vector (weights, path); } + void TckFactor::output_coefficients (const std::string& path) const { save_vector (coefficients, path);