Browse Source

🩹 Constrain UBL within mesh bounds (#24631)

Fixes #24630
Miguel Risco-Castillo 1 year ago
parent
commit
c918e90b8d
No account linked to committer's email address
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp

+ 6
- 4
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

@@ -423,10 +423,12 @@
423 423
       LIMIT(icell.x, 0, GRID_MAX_CELLS_X);
424 424
       LIMIT(icell.y, 0, GRID_MAX_CELLS_Y);
425 425
 
426
-      float z_x0y0 = z_values[icell.x  ][icell.y  ],  // z at lower left corner
427
-            z_x1y0 = z_values[icell.x+1][icell.y  ],  // z at upper left corner
428
-            z_x0y1 = z_values[icell.x  ][icell.y+1],  // z at lower right corner
429
-            z_x1y1 = z_values[icell.x+1][icell.y+1];  // z at upper right corner
426
+      const int8_t ncellx = _MIN(icell.x+1, GRID_MAX_CELLS_X),
427
+                   ncelly = _MIN(icell.y+1, GRID_MAX_CELLS_Y);
428
+      float z_x0y0 = z_values[icell.x][icell.y],  // z at lower left corner
429
+            z_x1y0 = z_values[ncellx ][icell.y],  // z at upper left corner
430
+            z_x0y1 = z_values[icell.x][ncelly ],  // z at lower right corner
431
+            z_x1y1 = z_values[ncellx ][ncelly ];  // z at upper right corner
430 432
 
431 433
       if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating planner.leveling_active (G29 A)
432 434
       if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points

Loading…
Cancel
Save