Description
MATLAB exits with a segmentation fault after running nonlinear optimization through the MATLAB wrapper when GTSAM is built with GTSAM_WITH_TBB=ON on macOS.
The same installed toolbox exits cleanly if no optimization is run, and rebuilding GTSAM with GTSAM_WITH_TBB=OFF removes the crash.
Steps to reproduce
- Configure and install GTSAM with the MATLAB toolbox enabled and TBB enabled.
cmake -S . -B build \
-DGTSAM_INSTALL_MATLAB_TOOLBOX=ON \
-DGTSAM_WITH_TBB=ON
cmake --build build -j6
cmake --install build
-
Start MATLAB and add the installed toolbox root to the path.
-
Run this minimal repro:
restoredefaultpath
addpath('/Users/dellaert/gtsam_toolbox')
import gtsam.*
priorNoise = noiseModel.Diagonal.Sigmas([0.3;0.3;0.1]);
odometryNoise = noiseModel.Diagonal.Sigmas([0.2;0.2;0.1]);
graph = NonlinearFactorGraph;
graph.add(PriorFactorPose2(1, Pose2(0,0,0), priorNoise));
graph.add(BetweenFactorPose2(1,2,Pose2(2,0,0), odometryNoise));
graph.add(BetweenFactorPose2(2,3,Pose2(2,0,0), odometryNoise));
initial = Values;
initial.insert(1, Pose2(0.5,0,0.2));
initial.insert(2, Pose2(2.3,0.1,-0.2));
initial.insert(3, Pose2(4.1,0.1,0.1));
optimizer = LevenbergMarquardtOptimizer(graph, initial);
result = optimizer.optimizeSafely();
exit
- MATLAB crashes during exit with a segmentation fault.
Expected behavior
MATLAB should exit cleanly after optimization.
Environment
- GTSAM commit:
23147828906c2df50c4772f2863de332c7d92f67
- MATLAB:
25.2.0.3177638 (R2025b) Update 5
- OS: macOS
26.3.2 on Apple Silicon
- Installed toolbox path used for repro:
/Users/dellaert/gtsam_toolbox
Additional information
restoredefaultpath; addpath('/Users/dellaert/gtsam_toolbox'); exit exits cleanly.
import gtsam.*; Pose2(); exit exits cleanly.
- Evaluating
graph.error(initial) exits cleanly.
- Constructing
LevenbergMarquardtOptimizer(graph, initial) without running optimization exits cleanly.
- Explicitly deleting wrapped objects before
exit does not prevent the crash.
- Setting
TBB_NUM_THREADS=1 does not prevent the crash.
OdometryExample also reproduces the same exit crash with TBB enabled.
- Rebuilding with
-DGTSAM_WITH_TBB=OFF makes the same repro exit cleanly.
Description
MATLAB exits with a segmentation fault after running nonlinear optimization through the MATLAB wrapper when GTSAM is built with
GTSAM_WITH_TBB=ONon macOS.The same installed toolbox exits cleanly if no optimization is run, and rebuilding GTSAM with
GTSAM_WITH_TBB=OFFremoves the crash.Steps to reproduce
cmake -S . -B build \ -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON \ -DGTSAM_WITH_TBB=ON cmake --build build -j6 cmake --install buildStart MATLAB and add the installed toolbox root to the path.
Run this minimal repro:
Expected behavior
MATLAB should exit cleanly after optimization.
Environment
23147828906c2df50c4772f2863de332c7d92f6725.2.0.3177638 (R2025b) Update 526.3.2on Apple Silicon/Users/dellaert/gtsam_toolboxAdditional information
restoredefaultpath; addpath('/Users/dellaert/gtsam_toolbox'); exitexits cleanly.import gtsam.*; Pose2(); exitexits cleanly.graph.error(initial)exits cleanly.LevenbergMarquardtOptimizer(graph, initial)without running optimization exits cleanly.exitdoes not prevent the crash.TBB_NUM_THREADS=1does not prevent the crash.OdometryExamplealso reproduces the same exit crash with TBB enabled.-DGTSAM_WITH_TBB=OFFmakes the same repro exit cleanly.