Browse Source

Prevent null pointer crash in Endstops::update

Thanks to Evgeny Kotsuba!
pull/1/head
Scott Lahteine 7 years ago
parent
commit
a5c6d3c7b8
  1. 184
      Marlin/src/module/endstops.cpp

184
Marlin/src/module/endstops.cpp

@ -448,119 +448,123 @@ void Endstops::update() {
/** /**
* Check and update endstops according to conditions * Check and update endstops according to conditions
*/ */
if (X_MOVE_TEST) { if (stepper.current_block) {
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
#if HAS_X_MIN if (X_MOVE_TEST) {
#if ENABLED(X_DUAL_ENDSTOPS) if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
UPDATE_ENDSTOP_BIT(X, MIN); #if HAS_X_MIN
#if HAS_X2_MIN #if ENABLED(X_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(X2, MIN); UPDATE_ENDSTOP_BIT(X, MIN);
#if HAS_X2_MIN
UPDATE_ENDSTOP_BIT(X2, MIN);
#else
COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
#endif
test_dual_x_endstops(X_MIN, X2_MIN);
#else #else
COPY_BIT(current_endstop_bits, X_MIN, X2_MIN); if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
#endif #endif
test_dual_x_endstops(X_MIN, X2_MIN);
#else
if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
#endif #endif
#endif }
} else { // +direction
else { // +direction #if HAS_X_MAX
#if HAS_X_MAX #if ENABLED(X_DUAL_ENDSTOPS)
#if ENABLED(X_DUAL_ENDSTOPS) UPDATE_ENDSTOP_BIT(X, MAX);
UPDATE_ENDSTOP_BIT(X, MAX); #if HAS_X2_MAX
#if HAS_X2_MAX UPDATE_ENDSTOP_BIT(X2, MAX);
UPDATE_ENDSTOP_BIT(X2, MAX); #else
COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
#endif
test_dual_x_endstops(X_MAX, X2_MAX);
#else #else
COPY_BIT(current_endstop_bits, X_MAX, X2_MAX); if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
#endif #endif
test_dual_x_endstops(X_MAX, X2_MAX);
#else
if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
#endif #endif
#endif }
} }
}
if (Y_MOVE_TEST) { if (Y_MOVE_TEST) {
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
#if HAS_Y_MIN #if HAS_Y_MIN
#if ENABLED(Y_DUAL_ENDSTOPS) #if ENABLED(Y_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(Y, MIN); UPDATE_ENDSTOP_BIT(Y, MIN);
#if HAS_Y2_MIN #if HAS_Y2_MIN
UPDATE_ENDSTOP_BIT(Y2, MIN); UPDATE_ENDSTOP_BIT(Y2, MIN);
#else
COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
#endif
test_dual_y_endstops(Y_MIN, Y2_MIN);
#else #else
COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN); UPDATE_ENDSTOP(Y, MIN);
#endif #endif
test_dual_y_endstops(Y_MIN, Y2_MIN);
#else
UPDATE_ENDSTOP(Y, MIN);
#endif #endif
#endif }
} else { // +direction
else { // +direction #if HAS_Y_MAX
#if HAS_Y_MAX #if ENABLED(Y_DUAL_ENDSTOPS)
#if ENABLED(Y_DUAL_ENDSTOPS) UPDATE_ENDSTOP_BIT(Y, MAX);
UPDATE_ENDSTOP_BIT(Y, MAX); #if HAS_Y2_MAX
#if HAS_Y2_MAX UPDATE_ENDSTOP_BIT(Y2, MAX);
UPDATE_ENDSTOP_BIT(Y2, MAX); #else
COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
#endif
test_dual_y_endstops(Y_MAX, Y2_MAX);
#else #else
COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX); UPDATE_ENDSTOP(Y, MAX);
#endif #endif
test_dual_y_endstops(Y_MAX, Y2_MAX);
#else
UPDATE_ENDSTOP(Y, MAX);
#endif #endif
#endif }
} }
}
if (Z_MOVE_TEST) { if (Z_MOVE_TEST) {
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up. if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
#if HAS_Z_MIN #if HAS_Z_MIN
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(Z, MIN); UPDATE_ENDSTOP_BIT(Z, MIN);
#if HAS_Z2_MIN #if HAS_Z2_MIN
UPDATE_ENDSTOP_BIT(Z2, MIN); UPDATE_ENDSTOP_BIT(Z2, MIN);
#else #else
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN); COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
#endif #endif
test_dual_z_endstops(Z_MIN, Z2_MIN); test_dual_z_endstops(Z_MIN, Z2_MIN);
#else
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
#else #else
UPDATE_ENDSTOP(Z, MIN); #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
#else
UPDATE_ENDSTOP(Z, MIN);
#endif
#endif #endif
#endif #endif
#endif
// When closing the gap check the enabled probe // When closing the gap check the enabled probe
#if ENABLED(Z_MIN_PROBE_ENDSTOP) #if ENABLED(Z_MIN_PROBE_ENDSTOP)
if (z_probe_enabled) { if (z_probe_enabled) {
UPDATE_ENDSTOP(Z, MIN_PROBE); UPDATE_ENDSTOP(Z, MIN_PROBE);
if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE); if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
} }
#endif #endif
} }
else { // Z +direction. Gantry up, bed down. else { // Z +direction. Gantry up, bed down.
#if HAS_Z_MAX #if HAS_Z_MAX
// Check both Z dual endstops // Check both Z dual endstops
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(Z, MAX); UPDATE_ENDSTOP_BIT(Z, MAX);
#if HAS_Z2_MAX #if HAS_Z2_MAX
UPDATE_ENDSTOP_BIT(Z2, MAX); UPDATE_ENDSTOP_BIT(Z2, MAX);
#else #else
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX); COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
#endif
test_dual_z_endstops(Z_MAX, Z2_MAX);
// If this pin is not hijacked for the bed probe
// then it belongs to the Z endstop
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
UPDATE_ENDSTOP(Z, MAX);
#endif #endif
test_dual_z_endstops(Z_MAX, Z2_MAX);
// If this pin is not hijacked for the bed probe
// then it belongs to the Z endstop
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
UPDATE_ENDSTOP(Z, MAX);
#endif #endif
#endif }
} }
}
} // stepper.current_block
old_endstop_bits = current_endstop_bits; old_endstop_bits = current_endstop_bits;

Loading…
Cancel
Save