Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running "layout" example #104

Closed
Blatko1 opened this issue Feb 25, 2022 · 3 comments
Closed

Error when running "layout" example #104

Blatko1 opened this issue Feb 25, 2022 · 3 comments

Comments

@Blatko1
Copy link

Blatko1 commented Feb 25, 2022

Running layout example on the newest version 0.7.0 prints this error message;

thread 'main' panicked at 'attempt to subtract with overflow',
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\panicking.rs:498
   1: core::panicking::panic_fmt
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\panicking.rs:107
   2: core::panicking::panic
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\panicking.rs:48
   3: fontdue::layout::Layout<tuple$<> >::append<tuple$<>,fontdue::font::Font>
             at .\src\layout.rs:448
   4: layout::main
             at .\examples\layout.rs:24
   5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\examples\layout.exe` (exit code: 101)

It seems to fail in this line of code:

layout.append(fonts, &TextStyle::new("Hello ", 35.0, 0));

where the subtraction happens:

if linebreak >= self.linebreak_prev {
                self.linebreak_prev = linebreak;
                self.linebreak_pos = self.current_pos;
                self.linebreak_idx = self.glyphs.len() - 1; // <--- HERE
            }
@Blatko1
Copy link
Author

Blatko1 commented Feb 25, 2022

Changing line 448:

if linebreak >= self.linebreak_prev {
                self.linebreak_prev = linebreak;
                self.linebreak_pos = self.current_pos;
                self.linebreak_idx = (self.glyphs.len() - 1).min(0);  // <--- CHANGED
            }

and changing line 498:

if let Some(line) = self.line_metrics.last_mut() {
            line.padding = self.max_width - (self.current_pos - self.start_pos);
            line.line_end = (self.glyphs.len() - 1).min(0); // <--- CHANGED
        }

in src/layout seems to fix the problem.

@mooman219
Copy link
Owner

It doesn't actually cause a logic issue, there's a check later on for this. That's unfortunate this triggers an error for you, I'll resolve it

@mooman219
Copy link
Owner

0.7.1 published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants