Skip to content

Commit

Permalink
swr: Fix panic when drawing clipped text
Browse files Browse the repository at this point in the history
In some case, when the clip is, eg on a 0.25 of a pixel, but the offset is 0.75,
(such that the begining of the glyph starts at 0.5) difference in
rounding in different computation can result in a width which is one
pixel bigger than the source image.
I couldn't reproduce this in a testcase, but this can be reproduced
while resizing or scrolling through a TextEdit

I think this fixes #2957

The panic fixed by this commit looks like this:
```
thread 'main' panicked at 'index out of bounds: the len is 131 but the index is 131', /home/olivier/slint/internal/core/software_renderer/draw_functions.rs:81:19
stack backtrace:
   3: i_slint_core::software_renderer::draw_functions::draw_texture_line
             at ./internal/core/software_renderer/draw_functions.rs:81:19
   4: <i_slint_core::software_renderer::RenderToBuffer<T> as i_slint_core::software_renderer::ProcessScene>::process_shared_image_buffer
             at ./internal/core/software_renderer.rs:1023:13
   5: i_slint_core::software_renderer::SceneBuilder<T>::draw_text_paragraph::{{closure}}
             at ./internal/core/software_renderer.rs:1404:37
   6: i_slint_core::textlayout::TextParagraphLayout<Font>::layout_lines::{{closure}}
             at ./internal/core/textlayout.rs:219:17
```
  • Loading branch information
ogoffart committed Jul 7, 2023
1 parent c0ac2ac commit 4a56531
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project are documented in this file.

- Fixed compiler panics when some complex expressions are used for the model expression in `for` (#2977)
- Native style: Fixed support for floating point ranges in Slider.
- Fixed panics in the software renderer related to text rendering.

### Slint Language

Expand Down
2 changes: 1 addition & 1 deletion internal/core/software_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ impl<'a, T: ProcessScene> SceneBuilder<'a, T> {
if geometry.is_empty() {
continue;
}
let origin = (geometry.origin - offset.round()).cast::<usize>();
let origin = (geometry.origin - offset.round()).round().cast::<usize>();
let actual_x = origin.x - src_rect.origin.x as usize;
let actual_y = origin.y - src_rect.origin.y as usize;
let stride = glyph.width.get() as u16;
Expand Down

0 comments on commit 4a56531

Please sign in to comment.