From f2fa2da3a58bb8680631e40beeed0b9ea488eec2 Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Wed, 22 Jan 2020 15:40:08 -0600 Subject: [PATCH] Rearrange init some to fix a crash, details: mr was not being intialized before it was being used by the stepper intialization. Also added a check to prevent it from happening from other places. --- g2core/main.cpp | 2 +- g2core/planner.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/g2core/main.cpp b/g2core/main.cpp index 129e73c4..e94cb3e1 100644 --- a/g2core/main.cpp +++ b/g2core/main.cpp @@ -100,11 +100,11 @@ void application_init_machine(void) { cm = &cm1; // set global canonical machine pointer to primary machine cm->machine_state = MACHINE_INITIALIZING; + canonical_machine_inits(); // combined inits for CMs and planner - do before anything might use cm or mr! stepper_init(); // stepper subsystem encoder_init(); // virtual encoders gpio_init(); // inputs and outputs - canonical_machine_inits(); // combined inits for CMs and planner } void application_init_startup(void) diff --git a/g2core/planner.cpp b/g2core/planner.cpp index 0d0e4d48..40d97a8c 100644 --- a/g2core/planner.cpp +++ b/g2core/planner.cpp @@ -264,6 +264,12 @@ void mp_set_runtime_position(uint8_t axis, const float position) { mr->position[ void mp_set_steps_to_runtime_position() { + if (mr == nullptr) { +#if IN_DEBUGGER + __asm__ volatile("BKPT 1"); // mp_set_steps_to_runtime_position called with null mr! +#endif + return; + } float step_position[MOTORS]; // There use to be a call to kn_inverse_kinematics here, but we don't do that now, instead we call kn->sync_encoders() // after handling the steps, allowing the kinematics to intelligently handle the offset of step and position.