Commit Graph

4 Commits

Author SHA1 Message Date
SoftFever
3b445905d1 Fix out-of-bounds reads in the multi-extruder flush-volume matrix
flush_volumes_matrix stores one (filaments x filaments) block per nozzle,
but set_extruder, WipeTower2::extract_wipe_volumes and the PresetBundle
rebuild indexed each block with filament_colour.size() as the row stride.
When the stored matrix does not match that assumption (a legacy project, or
a just-switched printer -- e.g. a single 2x2 block while nozzle_diameter has
2 entries) the index runs past the sliced block and reads out of bounds.

The read is undefined, so its value depends on the C++ std-lib/allocator
layout: identical across Linux architectures but different on macOS/Windows.
That surfaced as the "Toolchange temperature commands are unchanged when the
wipe tower wait is off" regression failing on Linux CI while passing on
macOS/Windows, and crashing hardened (-O0, _GLIBCXX_ASSERTIONS) builds.

- Centralize the block-dimension derivation in get_flush_volumes_matrix_dims
  (sqrt(size / nozzles) with a filaments^2 * nozzles == size check and a
  single-block fallback) and use it wherever the matrix is sliced/indexed;
  bounds-guard the reads as defense in depth. It weighs both options that
  claim to say how many blocks are stored, since either can be stale:
  flush_multiplier, written with the matrix in the project config, and
  nozzle_diameter, which changes the moment a printer is selected.
- PresetBundle::update_multi_material_filament_presets: rebuild the matrix on
  a nozzle-count-only change too (the old per-block gate missed those), and
  seed a brand-new nozzle from the first nozzle's tuned block.
- is_flush_config_modified: stride the stored matrix by its own dimension
  rather than the current filament count, and bound the nozzle loop by the
  printer's extruder count, which CalcFlushingVolumes indexes as well.
- is_flushing_matrix_error: the same derivation, which additionally divided
  by zero on an empty flush_multiplier.
- update_slice_warnings: guard nozzle_hrc_lists, which is sized by the
  nullable nozzle_type option and can be shorter than the extruder count.

With the read fixed the emitted trace is deterministic across builds and
platforms, so regenerate the golden from it and stop comparing the rounded
"time: <n>s" preheat comment (the tolerant lead time already carries that
timing). Add unit tests for the flush-matrix rebuild and dimension logic.
2026-08-07 14:21:26 +08:00
SoftFever
408db4b3b0 Wait for the toolchange temperature on the wipe tower
Adds a printer option that picks up the new tool without a blocking temperature
wait, travels to the wipe tower, and waits there right before purging, parked
beside the tower so the ooze from the heat-up lands next to it rather than on the
model. The incoming filament's target is raised ahead of the tool change, so the
heat-up overlaps both the change itself and the travel to the tower.

Off by default, and only offered for multi-extruder printers using a Type 2 wipe
tower; the generic toolchanger profile enables it.
2026-08-06 12:24:00 +08:00
Kris Austin
6fda82476d fix: out-of-bounds read computing tool-ordering max layer height (#14665)
* fix: out-of-bounds read computing tool-ordering max layer height

calc_max_layer_height() loops over the extruder count (nozzle_diameter)
but indexes max_layer_height with the same counter, reading past the end
when that array is shorter. Silent on release builds, aborts under a
bounds-checked STL (_GLIBCXX_ASSERTIONS).

Read via get_at(), which falls back to the first entry when the index is
out of range, as Slicing.cpp already does for this option.

Add a fff_print regression test slicing a two-extruder printer with a
single-entry max_layer_height.

* docs: clarify how max_layer_height ends up short in the regression test

Normalization sizes it to the filament count under single_extruder_multi_material,
not "a mismatch a profile can ship" as the earlier comment guessed.
2026-07-09 15:47:57 +08:00
raistlin7447
29f31b9b38 fff_print: a maintainable testing framework (proposal + coverage) (#14426)
* fix: initialize Print::m_isBBLPrinter

Built outside the GUI/CLI (headless tests, embedded use) the member was read
uninitialized: is_BBL_printer()/wipe_tower_type() feed it into ToolOrdering,
which then non-deterministically dropped per-feature filament assignments.
Default it to false, the value the GUI and CLI already assign for non-Bambu
printers.

* docs(test): add the fff_print testing contract

tests/fff_print/README.md codifies how the suite is organized: one file per
subsystem (each owning both in-memory and emitted-G-code assertions), flat
behavioral test names with a single [Subsystem] tag, a robust-tests guide,
the shared helpers, and an add-a-test checklist. Linked from tests/CLAUDE.md.

* test(fff_print): reorganize the suite to the contract and add coverage

Bring every subsystem into one file per the README: rename the test_data
harness to test_helpers; consolidate skirt/brim; split multi-filament and
cooling into their own files; disperse the test_printgcode grab-bag and the
end-to-end smoke scenario into focused tests; fold test_gcode into
test_gcodewriter. Standardize names and tags, align cube tests on the cube()
helper, and de-qualify the flagship files.

New coverage: multi-filament per-feature and per-object routing; a skirt/brim
behavior matrix (the #14333 rework, including brim ears, with regression
coverage for #14319 and #14366); resolved extrusion-width and config
comments; custom-G-code placeholders; fan control and speed-marker
consumption.

Re-enable three slice tests previously tagged [NotWorking]: the clipper
"Coordinate outside allowed range" error that disabled them was specific to a
past CI runner environment and no longer reproduces.

* test(fff_print): tag arm64-flaky skirt/brim tests NotWorking

Four skirt/brim slice tests intermittently throw ClipperLib's "Coordinate
outside allowed range" on the macOS and Windows arm64 CI toolchains (an FP
divergence, not a slicing bug; see PR #14207). Linux x86_64 and aarch64 are
unaffected. Tag them [NotWorking] so ctest -LE NotWorking skips them.

* test(fff_print): re-enable the arm64 skirt/brim tests

These were tagged [NotWorking] as a stopgap when myfork's daily-driver build
combined them with the cross-platform CI on a base that predated upstream's
m_origin fix (99dea01cc3). With upstream merged in, Print::m_origin is
initialized and the "Coordinate outside allowed range" throw is gone, so the
tests pass on macOS/Windows arm64. Drop the tags.
2026-07-06 22:24:24 +08:00