Skip to content

MATLAB macOS R2025b: exit crash after nonlinear optimization when GTSAM is built with TBB #2489

Description

@dellaert

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

  1. 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
  1. Start MATLAB and add the installed toolbox root to the path.

  2. 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
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions