Skip to content

Commit

Permalink
Fix runtime panic with colpan or rowspan set to zero
Browse files Browse the repository at this point in the history
Fix panic:
```
panicked at internal/core/layout.rs:459:33:
index out of bounds: the len is 2 but the index is 2
```
  • Loading branch information
ogoffart committed Jan 16, 2025
1 parent 62d9f8b commit a40a5c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/core/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ mod grid_internal {
spacing: Coord,
size: Option<Coord>,
) -> Vec<LayoutData> {
let mut num = 0;
let mut num = 0usize;
for cell in data {
num = num.max(cell.col_or_row + cell.span);
num = num.max(cell.col_or_row as usize + cell.span.max(1) as usize);
}
if num < 1 {
return Default::default();
}
let mut layout_data = alloc::vec![grid_internal::LayoutData { stretch: 1., ..Default::default() }; num as usize];
let mut layout_data =
alloc::vec![grid_internal::LayoutData { stretch: 1., ..Default::default() }; num];
let mut has_spans = false;
for cell in data {
let constraint = &cell.constraint;
Expand Down
11 changes: 8 additions & 3 deletions tests/cases/layout/grid_span.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

TestCase := Window {
component TestCase inherits Window {
width: 400phx;
height: 400phx;

Expand Down Expand Up @@ -44,12 +44,17 @@ TestCase := Window {
horizontal_stretch: 10;
vertical_stretch: 10;
}
zero2 := Rectangle {
col: 5;
colspan: 0;
}
}

property <bool> test: {
out property <bool> test: {
rr.x == 50phx && rr.y == 50phx && rr.width == 30phx && rr.height == (200phx - 10phx) / 2 &&
rb.width == 40phx && rg.width == 20phx && rg.height == (400phx - 200phx - 100phx - 20phx) / 2 &&
zero.height == 0 && zero.width == rb.width && zero.x == rb.x && zero.y == rg.y
zero.height == 0 && zero.width == rb.width && zero.x == rb.x && zero.y == rg.y &&
zero2.height == rg.height && zero2.width == 0 && zero2.x > rb.x && zero2.y == rg.y

}

Expand Down

0 comments on commit a40a5c7

Please sign in to comment.