Procházet zdrojové kódy

Prevent null pointer crash in Endstops::update

Thanks to Evgeny Kotsuba!
Scott Lahteine před 7 roky
rodič
revize
a5c6d3c7b8
1 změnil soubory, kde provedl 94 přidání a 90 odebrání
  1. 94
    90
      Marlin/src/module/endstops.cpp

+ 94
- 90
Marlin/src/module/endstops.cpp Zobrazit soubor

@@ -448,119 +448,123 @@ void Endstops::update() {
448 448
   /**
449 449
    * Check and update endstops according to conditions
450 450
    */
451
-  if (X_MOVE_TEST) {
452
-    if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
453
-      #if HAS_X_MIN
454
-        #if ENABLED(X_DUAL_ENDSTOPS)
455
-          UPDATE_ENDSTOP_BIT(X, MIN);
456
-          #if HAS_X2_MIN
457
-            UPDATE_ENDSTOP_BIT(X2, MIN);
451
+  if (stepper.current_block) {
452
+
453
+    if (X_MOVE_TEST) {
454
+      if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
455
+        #if HAS_X_MIN
456
+          #if ENABLED(X_DUAL_ENDSTOPS)
457
+            UPDATE_ENDSTOP_BIT(X, MIN);
458
+            #if HAS_X2_MIN
459
+              UPDATE_ENDSTOP_BIT(X2, MIN);
460
+            #else
461
+              COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
462
+            #endif
463
+            test_dual_x_endstops(X_MIN, X2_MIN);
458 464
           #else
459
-            COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
465
+            if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
460 466
           #endif
461
-          test_dual_x_endstops(X_MIN, X2_MIN);
462
-        #else
463
-          if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
464 467
         #endif
465
-      #endif
466
-    }
467
-    else { // +direction
468
-      #if HAS_X_MAX
469
-        #if ENABLED(X_DUAL_ENDSTOPS)
470
-          UPDATE_ENDSTOP_BIT(X, MAX);
471
-          #if HAS_X2_MAX
472
-            UPDATE_ENDSTOP_BIT(X2, MAX);
468
+      }
469
+      else { // +direction
470
+        #if HAS_X_MAX
471
+          #if ENABLED(X_DUAL_ENDSTOPS)
472
+            UPDATE_ENDSTOP_BIT(X, MAX);
473
+            #if HAS_X2_MAX
474
+              UPDATE_ENDSTOP_BIT(X2, MAX);
475
+            #else
476
+              COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
477
+            #endif
478
+            test_dual_x_endstops(X_MAX, X2_MAX);
473 479
           #else
474
-            COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
480
+            if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
475 481
           #endif
476
-          test_dual_x_endstops(X_MAX, X2_MAX);
477
-        #else
478
-          if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
479 482
         #endif
480
-      #endif
483
+      }
481 484
     }
482
-  }
483 485
 
484
-  if (Y_MOVE_TEST) {
485
-    if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
486
-      #if HAS_Y_MIN
487
-        #if ENABLED(Y_DUAL_ENDSTOPS)
488
-          UPDATE_ENDSTOP_BIT(Y, MIN);
489
-          #if HAS_Y2_MIN
490
-            UPDATE_ENDSTOP_BIT(Y2, MIN);
486
+    if (Y_MOVE_TEST) {
487
+      if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
488
+        #if HAS_Y_MIN
489
+          #if ENABLED(Y_DUAL_ENDSTOPS)
490
+            UPDATE_ENDSTOP_BIT(Y, MIN);
491
+            #if HAS_Y2_MIN
492
+              UPDATE_ENDSTOP_BIT(Y2, MIN);
493
+            #else
494
+              COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
495
+            #endif
496
+            test_dual_y_endstops(Y_MIN, Y2_MIN);
491 497
           #else
492
-            COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
498
+            UPDATE_ENDSTOP(Y, MIN);
493 499
           #endif
494
-          test_dual_y_endstops(Y_MIN, Y2_MIN);
495
-        #else
496
-          UPDATE_ENDSTOP(Y, MIN);
497 500
         #endif
498
-      #endif
499
-    }
500
-    else { // +direction
501
-      #if HAS_Y_MAX
502
-        #if ENABLED(Y_DUAL_ENDSTOPS)
503
-          UPDATE_ENDSTOP_BIT(Y, MAX);
504
-          #if HAS_Y2_MAX
505
-            UPDATE_ENDSTOP_BIT(Y2, MAX);
501
+      }
502
+      else { // +direction
503
+        #if HAS_Y_MAX
504
+          #if ENABLED(Y_DUAL_ENDSTOPS)
505
+            UPDATE_ENDSTOP_BIT(Y, MAX);
506
+            #if HAS_Y2_MAX
507
+              UPDATE_ENDSTOP_BIT(Y2, MAX);
508
+            #else
509
+              COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
510
+            #endif
511
+            test_dual_y_endstops(Y_MAX, Y2_MAX);
506 512
           #else
507
-            COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
513
+            UPDATE_ENDSTOP(Y, MAX);
508 514
           #endif
509
-          test_dual_y_endstops(Y_MAX, Y2_MAX);
510
-        #else
511
-          UPDATE_ENDSTOP(Y, MAX);
512 515
         #endif
513
-      #endif
516
+      }
514 517
     }
515
-  }
516 518
 
517
-  if (Z_MOVE_TEST) {
518
-    if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
519
-      #if HAS_Z_MIN
520
-        #if ENABLED(Z_DUAL_ENDSTOPS)
521
-          UPDATE_ENDSTOP_BIT(Z, MIN);
522
-          #if HAS_Z2_MIN
523
-            UPDATE_ENDSTOP_BIT(Z2, MIN);
524
-          #else
525
-            COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
526
-          #endif
527
-          test_dual_z_endstops(Z_MIN, Z2_MIN);
528
-        #else
529
-          #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
530
-            if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
519
+    if (Z_MOVE_TEST) {
520
+      if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
521
+        #if HAS_Z_MIN
522
+          #if ENABLED(Z_DUAL_ENDSTOPS)
523
+            UPDATE_ENDSTOP_BIT(Z, MIN);
524
+            #if HAS_Z2_MIN
525
+              UPDATE_ENDSTOP_BIT(Z2, MIN);
526
+            #else
527
+              COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
528
+            #endif
529
+            test_dual_z_endstops(Z_MIN, Z2_MIN);
531 530
           #else
532
-            UPDATE_ENDSTOP(Z, MIN);
531
+            #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
532
+              if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
533
+            #else
534
+              UPDATE_ENDSTOP(Z, MIN);
535
+            #endif
533 536
           #endif
534 537
         #endif
535
-      #endif
536 538
 
537
-      // When closing the gap check the enabled probe
538
-      #if ENABLED(Z_MIN_PROBE_ENDSTOP)
539
-        if (z_probe_enabled) {
540
-          UPDATE_ENDSTOP(Z, MIN_PROBE);
541
-          if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
542
-        }
543
-      #endif
544
-    }
545
-    else { // Z +direction. Gantry up, bed down.
546
-      #if HAS_Z_MAX
547
-        // Check both Z dual endstops
548
-        #if ENABLED(Z_DUAL_ENDSTOPS)
549
-          UPDATE_ENDSTOP_BIT(Z, MAX);
550
-          #if HAS_Z2_MAX
551
-            UPDATE_ENDSTOP_BIT(Z2, MAX);
552
-          #else
553
-            COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
539
+        // When closing the gap check the enabled probe
540
+        #if ENABLED(Z_MIN_PROBE_ENDSTOP)
541
+          if (z_probe_enabled) {
542
+            UPDATE_ENDSTOP(Z, MIN_PROBE);
543
+            if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
544
+          }
545
+        #endif
546
+      }
547
+      else { // Z +direction. Gantry up, bed down.
548
+        #if HAS_Z_MAX
549
+          // Check both Z dual endstops
550
+          #if ENABLED(Z_DUAL_ENDSTOPS)
551
+            UPDATE_ENDSTOP_BIT(Z, MAX);
552
+            #if HAS_Z2_MAX
553
+              UPDATE_ENDSTOP_BIT(Z2, MAX);
554
+            #else
555
+              COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
556
+            #endif
557
+            test_dual_z_endstops(Z_MAX, Z2_MAX);
558
+          // If this pin is not hijacked for the bed probe
559
+          // then it belongs to the Z endstop
560
+          #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
561
+            UPDATE_ENDSTOP(Z, MAX);
554 562
           #endif
555
-          test_dual_z_endstops(Z_MAX, Z2_MAX);
556
-        // If this pin is not hijacked for the bed probe
557
-        // then it belongs to the Z endstop
558
-        #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
559
-          UPDATE_ENDSTOP(Z, MAX);
560 563
         #endif
561
-      #endif
564
+      }
562 565
     }
563
-  }
566
+
567
+  } // stepper.current_block
564 568
 
565 569
   old_endstop_bits = current_endstop_bits;
566 570
 

Loading…
Zrušit
Uložit