mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-25 06:47:48 -05:00
# Description <!-- > Please provide a summary of the changes made in this PR. Include details such as: > * What issue does this PR address or fix? > * What new features or enhancements does this PR introduce? > * Are there any breaking changes or dependencies that need to be considered? --> Fixes #16693. After slicing, the Preview listed layer pauses one or more layers too high, and with two adjacent pauses one of them showed as layer 0. The G-code was always right: every pause is written at the correct height, before the correct layer. Only the Preview's layer numbering was wrong. ## Cause When the G-code processor reads a pause, color change or custom G-code tag, `OptionsZCorrector::set()` stores the index of that vertex in the move list. At the first extrusion after it, `update()` moves the vertex to that point so it renders at the new layer's height. A pause (and a color change) first flushes the time planner. The flush inserts actual speed moves ahead of the flushed blocks' moves, which all come before the vertex, so the stored index goes stale and points at an earlier move: the previous layer's last extrusion. `update()` then moves that extrusion past the travel to the next layer, with its old layer id, and erases a real move. The erase also shifts every later move down one, so the time blocks still queued for the travel and unretract after the pause point one move off; a Debug build trips `assert(curr_move.actual_feedrate == 0.0f)` in `TimeMachine::calculate_time` on a Marlin profile. This has been possible since actual speed moves were added. It became visible with the belt printer change that renumbers the Preview's layers on every change of a move's layer id (`f64b49ab52`): the out-of-order move now turns into two extra layers, the layer heights stop being sorted, and the legend's lookup misses. 2.4.2 is not affected. ## Changes - `OptionsZCorrector::on_moves_inserted()`, called at the end of `GCodeProcessor::calculate_time`, shifts the stored index by the moves the flush inserted before it, read from the block id map the same function already builds for the queued blocks. - `OptionsZCorrector::update()` returns the index it erased, and `process_G1` moves the queued blocks after it down by one. No change to the G-code, the time estimates of prints without pauses, or project files. # Screenshots/Recordings/Graphs <!-- > Please attach relevant screenshots to showcase the UI changes. > Please attach images that can help explain the changes. --> The reporter's cube with pauses at layers 55 and 56 (Z 11 and 11.2): main lists them at layers 56 and 60 and shows 132 layers for a 128-layer print; with this change they are at 55 and 56, and the slider shows 128 layers. Before: <img width="480" height="560" alt="legend-before-main" src="https://github.com/user-attachments/assets/d9604038-91c0-4574-8496-a7d9f49268cf" /> After: <img width="480" height="560" alt="legend-after-fix" src="https://github.com/user-attachments/assets/0ad4be7e-a258-4eaa-ae94-8eb66ef01fae" /> ## Tests <!-- > Please describe the tests that you have conducted to verify the changes made in this PR. --> - New test in `tests/fff_print/test_gcodeprocessor.cpp`, "A pause keeps the moves around it in order and on their own layers": three layers with a pause before the second; checks the pause's height and that layer ids and G-code lines never go backwards. It fails on main (the pause stays at Z 0.2 and a layer-0 extrusion lands after layer-1 moves) and passes with the change. - `fff_print` suite passes (484 tests, Release, Linux), including the `[GCodeTiming]` cases. - On Linux, sliced the issue's project with one and two pauses on the Anycubic Kobra 3 (Klipper) profile and checked the Preview legend and layer slider. Marlin is covered by the new test, which runs the processor with Marlin. - clang-tidy check passes. <!-- > A guide for users on how to download the artifacts from this PR. --> [How to Download Pull Requests Artifacts for Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)