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

RustType glyph pair kerning crashes when using DroidSansFallback.ttf font (possibly for other fonts too). #874

Closed
ghost opened this issue Nov 19, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Nov 19, 2016

This example program will crashs with change fonts: https://github.com/PistonDevelopers/conrod/blob/master/examples/text_edit.rs

#[macro_use] extern crate conrod;
extern crate find_folder;

// use std::path::Path;

use conrod::backend::piston::{self, Window, WindowEvents, OpenGL};
use conrod::backend::piston::event::UpdateEvent;

widget_ids! { 
    struct Ids { canvas, text_edit, scrollbar }
}

fn main() {
    const WIDTH: u32 = 360;
    const HEIGHT: u32 = 720;

    // Construct the window.
    let mut window: Window =
        piston::window::WindowSettings::new("Text Demo", [WIDTH, HEIGHT])
            .opengl(OpenGL::V3_2).exit_on_esc(true).build().unwrap();

    // Create the event loop.
    let mut events = WindowEvents::new();

    // Construct our `Ui`.
    let mut ui = conrod::UiBuilder::new([WIDTH as f64, HEIGHT as f64]).build();

    // A unique identifier for each widget.
    let ids = Ids::new(ui.widget_id_generator());


    // =============================================================
    // Add a `Font` to the `Ui`'s `font::Map` from file.
    ui.fonts.insert_from_file("/usr/share/fonts/TTF/DroidSansFallback.ttf").unwrap();  
    // =============================================================


    // Create a texture to use for efficiently caching text on the GPU.
    let mut text_texture_cache = piston::window::GlyphCache::new(&mut window, WIDTH, HEIGHT);

    // The image map describing each of our widget->image mappings (in our case, none).
    let image_map = conrod::image::Map::new();

    // Some starting text to edit.
    let mut demo_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
        Mauris aliquet porttitor tellus vel euismod. Integer lobortis volutpat bibendum. Nulla \
        finibus odio nec elit condimentum, rhoncus fermentum purus lacinia. Interdum et malesuada \
        fames ac ante ipsum primis in faucibus. Cras rhoncus nisi nec dolor bibendum pellentesque. \
        Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. \
        Quisque commodo nibh hendrerit nunc sollicitudin sodales. Cras vitae tempus ipsum. Nam \
        magna est, efficitur suscipit dolor eu, consectetur consectetur urna.".to_owned();

    // Poll events from the window.
    while let Some(event) = window.next_event(&mut events) {

        // Convert the piston event to a conrod event.
        if let Some(e) = piston::window::convert_event(event.clone(), &window) {
            ui.handle_event(e);
        }

        event.update(|_| set_ui(ui.set_widgets(), &ids, &mut demo_text));

        window.draw_2d(&event, |c, g| {
            if let Some(primitives) = ui.draw_if_changed() {
                fn texture_from_image<T>(img: &T) -> &T { img };
                piston::window::draw(c, g, primitives,
                                     &mut text_texture_cache,
                                     &image_map,
                                     texture_from_image);
            }
        });
    }

}

// Declare the `WidgetId`s and instantiate the widgets.
fn set_ui(ref mut ui: conrod::UiCell, ids: &Ids, demo_text: &mut String) {
    use conrod::{color, widget, Colorable, Positionable, Sizeable, Widget};

    widget::Canvas::new()
        .scroll_kids_vertically()
        .color(color::DARK_CHARCOAL)
        .set(ids.canvas, ui);

    for edit in widget::TextEdit::new(demo_text)
        .color(color::LIGHT_BLUE)
        .padded_w_of(ids.canvas, 20.0)
        .mid_top_of(ids.canvas)
        .align_text_x_middle()
        .line_spacing(2.5)
        .restrict_to_height(false) // Let the height grow infinitely and scroll.
        .set(ids.text_edit, ui)
    {
        *demo_text = edit;
    }

    widget::Scrollbar::y_axis(ids.canvas).auto_hide(true).set(ids.scrollbar, ui);
}
╭─mindcat@mindcat-linux-pc ~/workspace/tools/人民币大写  ‹master*› 
╰─➤  RUST_BACKTRACE=1 cargo run
   Compiling 人民币大写 v0.1.0 (file:///home/mindcat/workspace/tools/%E4%BA%BA%E6%B0%91%E5%B8%81%E5%A4%A7%E5%86%99)
    Finished debug [unoptimized + debuginfo] target(s) in 10.96 secs
     Running `target/debug/人民币大写`
thread 'main' panicked at 'attempt to subtract with overflow', /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.0/src/lib.rs:794
stack backtrace:
   1:     0x5621d1d529da - std::sys::imp::backtrace::tracing::imp::write::he3d1bfbdbf113480
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x5621d1d56b9f - std::panicking::default_hook::{{closure}}::h575f1b40d2e88f07
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:247
   3:     0x5621d1d54eb6 - std::panicking::default_hook::h3d5dccce8125d0cf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:263
   4:     0x5621d1d55567 - std::panicking::rust_panic_with_hook::h00b81bb3dcbd51f2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:451
   5:     0x5621d1d553f4 - std::panicking::begin_panic::ha6a0d553db9869ff
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:413
   6:     0x5621d1d55319 - std::panicking::begin_panic_fmt::h24d113aee3ee4081
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:397
   7:     0x5621d1d552a7 - rust_begin_unwind
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:373
   8:     0x5621d1d9112d - core::panicking::panic_fmt::he441b2ea2036b98a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/panicking.rs:69
   9:     0x5621d1d91064 - core::panicking::panic::haf296e94ad32f436
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/panicking.rs:49
  10:     0x5621d1a5b205 - <stb_truetype::FontInfo<Data>>::get_glyph_kern_advance::h51d458b9d335ed9e
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.0/src/lib.rs:794
  11:     0x5621d1a95e02 - rusttype::Font::pair_kerning::hb8b11e262e31664a
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/rusttype-0.2.1/src/lib.rs:410
  12:     0x5621d1af1344 - conrod::text::line::advance_width::{{closure}}::had33d94f54add31a
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/text.rs:1035
  13:     0x5621d1a146f5 - <core::option::Option<T>>::map::h0094652dc24e3919
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/option.rs:383
  14:     0x5621d1ab783f - conrod::text::line::advance_width::h979f0ae7c3d9931d
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/text.rs:1034
  15:     0x5621d1ab8775 - conrod::text::line::next_break_by_whitespace::hd699cac0971ce105
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/text.rs:1153
  16:     0x5621d1b0a585 - core::ops::FnMut::call_mut::h13ba10e2a1d2c302
  17:     0x5621d1ab9690 - <conrod::text::line::Infos<'a, F> as core::iter::iterator::Iterator>::next::h7381027e828cef49
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/text.rs:1320
  18:     0x5621d1a6acc2 - core::iter::iterator::Iterator::fold::h353e3acb193e9c46
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/iter/iterator.rs:1306
  19:     0x5621d1a6e86e - core::iter::iterator::Iterator::count::h1eb6a1f50b4f5c0d
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/iter/iterator.rs:170
  20:     0x5621d1acaec1 - <conrod::widget::text_edit::TextEdit<'a> as conrod::widget::Widget>::default_y_dimension::h15e768267e2e442f
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/widget/text_edit.rs:241
  21:     0x5621d19e8ee0 - conrod::widget::<impl conrod::position::Sizeable for W>::get_y_dimension::{{closure}}::hce022eb0efc3260c
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/widget/mod.rs:1226
  22:     0x5621d18e6b2e - <core::option::Option<T>>::unwrap_or_else::h341809acd29dd28c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/option.rs:358
  23:     0x5621d1962f2f - conrod::widget::<impl conrod::position::Sizeable for W>::get_y_dimension::h8fa48df30a8e485b
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/widget/mod.rs:1226
  24:     0x5621d1973524 - conrod::position::Sizeable::get_h::h8d70f9551c7704f0
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/position/mod.rs:737
  25:     0x5621d19ef1ff - conrod::position::Sizeable::get_wh::{{closure}}::h93635709689e16f5
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/position/mod.rs:748
  26:     0x5621d18fc43b - <core::option::Option<T>>::and_then::h687307e57e54a64c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/option.rs:578
  27:     0x5621d197442c - conrod::position::Sizeable::get_wh::h54af0e8fcef3d328
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/position/mod.rs:748
  28:     0x5621d195cda3 - conrod::widget::set_widget::h584dfac069abbeee
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/widget/mod.rs:861
  29:     0x5621d1964b3b - conrod::widget::Widget::set::h62ae645ff012cff4
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/conrod-0.46.2/./src/widget/mod.rs:780
  30:     0x5621d19d3c18 - $u4eba$$u6c11$$u5e01$$u5927$$u5199$::set_ui::h5208751dc8f209c5
                        at /home/mindcat/workspace/tools/人民币大写/src/main.rs:81
  31:     0x5621d19f6773 - $u4eba$$u6c11$$u5e01$$u5927$$u5199$::main::{{closure}}::h7210588b30266ec1
                        at /home/mindcat/workspace/tools/人民币大写/src/main.rs:57
  32:     0x5621d19a60b3 - <input::event::Event<I> as input::update::UpdateEvent>::update::hfcd7330366544418
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/pistoncore-input-0.14.0/src/update.rs:71
  33:     0x5621d19d36b0 - $u4eba$$u6c11$$u5e01$$u5927$$u5199$::main::h7afe71289f1371e6
                        at /home/mindcat/workspace/tools/人民币大写/src/main.rs:57
  34:     0x5621d1d5e67a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libpanic_unwind/lib.rs:97
  35:     0x5621d1d55f85 - std::rt::lang_start::h74b3afbdd8daef1c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:332
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:351
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/rt.rs:57
  36:     0x5621d19fa913 - main
  37:     0x7f903affb290 - __libc_start_main
  38:     0x5621d18c0fa9 - _start
  39:                0x0 - <unknown>

@mitchmindtree
Copy link
Contributor

Hey thanks for the report @mindcat 😸

Conrod uses dylanede/rusttype to load and render fonts. It looks like the way that rusttype calculates the kerning advance for this font might be the main culprit.

   9:     0x5621d1d91064 - core::panicking::panic::haf296e94ad32f436
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/panicking.rs:49
  10:     0x5621d1a5b205 - <stb_truetype::FontInfo<Data>>::get_glyph_kern_advance::h51d458b9d335ed9e
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.0/src/lib.rs:794
  11:     0x5621d1a95e02 - rusttype::Font::pair_kerning::hb8b11e262e31664a
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/rusttype-0.2.1/src/lib.rs:410
  12:     0x5621d1af1344 - conrod::text::line::advance_width::{{closure}}::had33d94f54add31a

Would it be possible for you to try running this rusttype example with your DroidSansFallback.ttf font and see if you run into the same error? If you continue to get the same error, it might be best to move this issue to the rusttype repo. If not, I'll be happy to look into this further 👍

@ghost
Copy link
Author

ghost commented Nov 19, 2016

@mitchmindtree

╭─mindcat@mindcat-linux-pc ~/workspace/rusttype  ‹master*› 
╰─➤  RUST_BACKTRACE=1 cargo run --example gpu_cache                                                                                                                 101 ↵
    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/examples/gpu_cache`
thread 'main' panicked at 'attempt to subtract with overflow', /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.0/src/lib.rs:794
stack backtrace:
   1:     0x55e730afb62a - std::sys::imp::backtrace::tracing::imp::write::he3d1bfbdbf113480
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x55e730aff82f - std::panicking::default_hook::{{closure}}::h575f1b40d2e88f07
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:247
   3:     0x55e730afdba6 - std::panicking::default_hook::h3d5dccce8125d0cf
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:263
   4:     0x55e730afe1f7 - std::panicking::rust_panic_with_hook::h00b81bb3dcbd51f2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:451
   5:     0x55e730afe084 - std::panicking::begin_panic::ha6a0d553db9869ff
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:413
   6:     0x55e730afdfa9 - std::panicking::begin_panic_fmt::h24d113aee3ee4081
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:397
   7:     0x55e730afdf37 - rust_begin_unwind
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:373
   8:     0x55e730b35b9d - core::panicking::panic_fmt::he441b2ea2036b98a
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/panicking.rs:69
   9:     0x55e730b35ad4 - core::panicking::panic::haf296e94ad32f436
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/panicking.rs:49
  10:     0x55e7307aa8f5 - <stb_truetype::FontInfo<Data>>::get_glyph_kern_advance::h97b4b4107e765071
                        at /home/mindcat/.cargo/registry/src/github.com-1ecc6299db9ec823/stb_truetype-0.2.0/src/lib.rs:794
  11:     0x55e73081f532 - rusttype::Font::pair_kerning::hbd51958f34961901
                        at /home/mindcat/workspace/rusttype/src/lib.rs:410
  12:     0x55e73082ff75 - gpu_cache::layout_paragraph::h80b2eef837a5d06d
                        at /home/mindcat/workspace/rusttype/examples/gpu_cache.rs:43
  13:     0x55e730830e01 - gpu_cache::main::h49ee56850d572cc0
                        at /home/mindcat/workspace/rusttype/examples/gpu_cache.rs:129
  14:     0x55e730b0730a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libpanic_unwind/lib.rs:97
  15:     0x55e730afec15 - std::rt::lang_start::h74b3afbdd8daef1c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:332
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:351
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/rt.rs:57
  16:     0x55e730837873 - main
  17:     0x7f1227db9290 - __libc_start_main
  18:     0x55e730763869 - _start
  19:                0x0 - <unknown>

Yes.

@mitchmindtree
Copy link
Contributor

@mindcat awesome thanks for that.

@ghost ghost changed the title Crashing fonts. Fonts crashing programs. Nov 20, 2016
@ghost
Copy link
Author

ghost commented Nov 20, 2016

@mitchmindtree You could suggest a new title for this problem :D

@mitchmindtree mitchmindtree changed the title Fonts crashing programs. RustType glyph pair kerning crashes when using DroidSansFallback.ttf font (possibly for other fonts too). Nov 23, 2016
@mitchmindtree
Copy link
Contributor

Going to close this in favour of dylanede/rusttype#30 (should be fixed by redox-os/stb_truetype-rs#5 anyways).

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

No branches or pull requests

1 participant