Skip to content

fix: all three PA calibration tests fail to print correctly - #231

Open
bugparty wants to merge 2 commits into
QIDITECH:mainfrom
bugparty:fix/pa-calib-eigen-oob-crash
Open

fix: all three PA calibration tests fail to print correctly#231
bugparty wants to merge 2 commits into
QIDITECH:mainfrom
bugparty:fix/pa-calib-eigen-oob-crash

Conversation

@bugparty

@bugparty bugparty commented Sep 6, 2026

Copy link
Copy Markdown

Problem

All three Pressure Advance calibrations — PA Line, PA Pattern and PA Tower — currently fail to print correctly. Debug builds abort outright:

qidi-studio: src/eigen/Eigen/src/Core/DenseCoeffsBase.h:364:
  Eigen::DenseCoeffsBase<Derived, 1>::Scalar&
  Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::Index, Eigen::Index)
  [with Derived = Eigen::Matrix<double, 2, 1, 2>]:
  Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.
Signal: SIGABRT (Aborted)

Cause

GCode::set_object_info() emits an EXCLUDE_OBJECT_DEFINE describing the area actually covered by the calibration pattern. first_v holds the polygon's first vertex so the ring can be closed at the end — the same role it plays in polygon_to_string() at GCode.cpp:8155, where it is correctly declared const auto.

Inside the loop it was then "assigned" with:

first_v(v.x() + ext_x, v.y());

On an already-constructed Vec2d this is not assignment. It resolves to Eigen's two-dimensional coefficient accessor

Scalar& DenseCoeffsBase<Derived, WriteAccessors>::operator()(Index row, Index col)

with both doubles truncated to indices. Vec2d is Eigen::Matrix<double, 2, 1, DontAlign> — matching Matrix<double, 2, 1, 2> in the assertion — so only (0,0) and (1,0) are in range. Real bed coordinates are not, and the bounds assertion fires.

Under NDEBUG the assertion is compiled out and the expression merely forms an out-of-bounds reference that is immediately discarded, so first_v was never actually written. The statement is dead code in every release build.

Fix

Remove the statement and declare first_v const, matching polygon_to_string().

The closing vertex must be vertex 0. Had the statement been a real assignment it would have left first_v at vertex 3 (the branch runs for i == 0 || i == 3), emitting a duplicated final point and an unclosed polygon — strictly worse than the current release behaviour. Making it const also lets the compiler reject this class of misuse at compile time.

Release behaviour is therefore unchanged, and Debug builds no longer abort.

Verification

Built on Fedora and exercised all three PA calibration modes; all now print correctly, where previously all three were broken.

https://claude.ai/code/session_01GX1HqJrRdEWvoiwXkfrLQH

The PA Line, PA Pattern and PA Tower calibrations all produced a wrong
EXCLUDE_OBJECT_DEFINE for the calibration area, and aborted outright on
Debug builds.

In GCode::set_object_info(), `first_v` holds the polygon's first vertex so
the ring can be closed at the end, exactly as polygon_to_string() does at
GCode.cpp:8155. Inside the loop it was then "assigned" with:

    first_v(v.x() + ext_x, v.y());

On an already-constructed Vec2d that is not assignment -- it resolves to
Eigen's two-dimensional coefficient accessor

    Scalar& DenseCoeffsBase<Derived, WriteAccessors>::operator()(Index, Index)

with both doubles truncated to indices. For a 2x1 vector only (0,0) and
(1,0) are valid, so real bed coordinates blow the bounds assertion:

    Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.

Under NDEBUG the assertion is compiled out and the expression forms an
out-of-bounds reference that is immediately discarded, so `first_v` was
never actually written. The statement is dead code in every release build.

Remove it and make `first_v` const, matching polygon_to_string(). The
closing vertex must be vertex 0; had the statement been a real assignment
it would have left `first_v` at vertex 3, emitting a duplicated final point
and an unclosed polygon. Behaviour is therefore unchanged for release
builds, and Debug builds no longer abort.

Verified on Fedora against all three PA calibration modes.

Claude-Session: https://claude.ai/code/session_01GX1HqJrRdEWvoiwXkfrLQH
Docstrings generation was requested by @bugparty.

The following files were modified:

* `src/libslic3r/GCode.cpp`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant