diff --git a/gtsam/base/treeTraversal-inst.h b/gtsam/base/treeTraversal-inst.h index 2d3c135ad..9cf9ad41c 100644 --- a/gtsam/base/treeTraversal-inst.h +++ b/gtsam/base/treeTraversal-inst.h @@ -107,9 +107,12 @@ namespace gtsam { tbb::task_list childTasks; BOOST_FOREACH(const boost::shared_ptr& child, node->children) { - // Process child in a subtask + // Process child in a subtask. Important: Run visitorPre before calling + // allocate_child so that if visitorPre throws an exception, we will not have + // allocated an extra child, this causes a TBB error. + const DATA childData = visitorPre(child, myData); childTasks.push_back(*new(allocate_child()) - PreOrderTask(child, visitorPre(child, myData), visitorPre, visitorPost, + PreOrderTask(child, childData, visitorPre, visitorPost, problemSizeThreshold, overThreshold)); }