GridLayout: repeated Row panics in layout.rs col_or_row_and_span when a row changes and the model grows in one batch
Bug: A GridLayout with a repeated Row panics in the grid solver when a row is changed in place and the model grows before the next frame, if a changed handler reads the cell's grid-assigned geometry.
thread panicked at internal/core/layout.rs:567:10:
index out of bounds: the len is 8 but the index is 8Reproduces on 1.18.0, 1.18.1 and current master (5ccf5b32ce), Rust code generator only. The same .slint driven through slint-interpreter with the same model operations does not panic.
Reduced test case
tests/cases/layout/issue_13723_grid_repeated_row_grow.slint, fails with the Rust test driver on master:
export struct RowData { v: int }
export component TestCase inherits Window {
width: 300px;
height: 300px;
in property <[RowData]> rows;
out property <int> width-changes;
GridLayout {
for r in root.rows: Row {
Rectangle {
min-width: 20px + r.v * 1px;
min-height: 20px;
changed width => { root.width-changes += 1; }
}
}
}
out property <bool> test: true;
}let instance = TestCase::new().unwrap();
let rows = Rc::new(VecModel::from(vec![RowData { v: 0 }]));
instance.set_rows(rows.clone().into());
slint_testing::mock_elapsed_time(16);
// Change row 0 in place and grow the model before the next frame.
rows.set_row_data(0, RowData { v: 5 });
rows.push(RowData { v: 0 });
slint_testing::mock_elapsed_time(16); // panics hereSLINT_TEST_FILTER=issue_13723 cargo test --manifest-path tests/Cargo.toml -p test-driver-rustExpected
Two rows, no panic. Row 0's cell is 25px wide, row 1's 20px.
Trigger conditions
All four are needed; removing any one makes it pass (each checked as a separate control):
- a repeated
Rowin aGridLayout; - a cell size bound to the row data (
min-width: 20px + r.v * 1px); - a
changedhandler on the cell's grid-assigned geometry (changed widthon the cell, or a child'schangedon a property bound to the cell'sx/width); - in one batch, before the next frame: a
set_row_datathat actually changes the row, and a row-count increase (pushorinsert; the order doesn't matter).
Not triggering: growth in its own frame; shrink instead of grow; set_row_data with the current value; set_vec with the grown contents; a changed handler on a non-geometry property.
Backtrace (master)
col_or_row_and_span
max_value
grid_internal::to_layout_data
solve_grid_layout
InnerTestCase::init::{closure#2} (the layout-cache binding)
... property binding evaluation ...
ChangeTracker::run_change_handlers
i_slint_backend_testing::mock_elapsed_timecol_or_row_and_span indexes the organized-cell vector (4 u16 per cell). "len 8, index 8" is a lookup of a third cell in data organized for two: to_layout_data iterates over a constraints list that already holds the grown row count while the organized data still describes the old one. The changed handler forces the layout solve from inside run_change_handlers rather than at the next render. That last paragraph is inferred from the stack and the trigger conditions, not verified in the generator.
Source: slint-ui/slint