diff --git a/src/emc/rs274ngc/interp_setup.cc b/src/emc/rs274ngc/interp_setup.cc index 80021e5a4b7..a0b27f6132f 100644 --- a/src/emc/rs274ngc/interp_setup.cc +++ b/src/emc/rs274ngc/interp_setup.cc @@ -117,7 +117,7 @@ setup::setup() : orient_valid(false), orient_pose{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, kins_ctx(nullptr), - kins_comp_id(0), + kins_comp_id(-1), kins_module{}, kins_joints(0), kins_angular_joints(0), diff --git a/src/emc/rs274ngc/interp_workplane.cc b/src/emc/rs274ngc/interp_workplane.cc index d1e626df12f..21cb5a57585 100644 --- a/src/emc/rs274ngc/interp_workplane.cc +++ b/src/emc/rs274ngc/interp_workplane.cc @@ -652,9 +652,9 @@ void Interp::kins_release(setup_pointer s) kinematicsUserFree(KINS_CTX(s)); s->kins_ctx = NULL; } - if (s->kins_comp_id > 0) { + if (s->kins_comp_id >= 0) { hal_exit(s->kins_comp_id); - s->kins_comp_id = 0; + s->kins_comp_id = -1; } } diff --git a/src/emc/rs274ngc/rs274ngc_pre.cc b/src/emc/rs274ngc/rs274ngc_pre.cc index 8ab946e80b0..2e9c2a04990 100644 --- a/src/emc/rs274ngc/rs274ngc_pre.cc +++ b/src/emc/rs274ngc/rs274ngc_pre.cc @@ -812,6 +812,10 @@ int Interp::exit() } } + // task exits without destroying the interpreter: let go of the HAL + // component the kinematics was evaluated through, or it outlives task + // and the shutdown waits for it; the next use loads it again + kins_release(&_setup); return INTERP_OK; }