Some fonts can cause rusttype to panic during Cache::cache_queued()
Created by: Boscop
I have a font called 'Bank Gothic Light.ttf' and when I try to render a string with it with Rusttype, I get this runtime error:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/
libcore\option.rs:323
stack backtrace:
0: 0x13c4448 - std::rt::lang_start::h14cbded5fe3cd915
1: 0x13c4cba - std::panicking::rust_panic_with_hook::hcd9d05f53fa0dafc
2: 0x13c4b56 - std::panicking::begin_panic_fmt::hb0a7126ee57cdd27
3: 0x13c4a0b - rust_begin_unwind
4: 0x11d8645 - rusttype::rasterizer::rasterize::{{closure}}<closure>
at C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\r
usttype-0.2.1\src\rasterizer.rs:199
5: 0x1147e9c - collections::slice::insertion_sort<(rusttype::geometry::Line,
rusttype::geometry::Rect<f32>),closure>
at C:\bot\slave\nightly-dist-rustc-win-msvc-32\build\src\libcoll
ections\slice.rs:1304
6: 0x1145902 - collections::slice::merge_sort<(rusttype::geometry::Line, rus
ttype::geometry::Rect<f32>),closure>
at C:\bot\slave\nightly-dist-rustc-win-msvc-32\build\src\libcoll
ections\slice.rs:1345
7: 0x114924a - collections::slice::{{impl}}::sort_by<(rusttype::geometry::Li
ne, rusttype::geometry::Rect<f32>),closure>
at C:\bot\slave\nightly-dist-rustc-win-msvc-32\build\src\libcoll
ections\slice.rs:1086
8: 0x11c5801 - rusttype::rasterizer::rasterize<closure>
at C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\r
usttype-0.2.1\src\rasterizer.rs:199
9: 0x11c904f - rusttype::PositionedGlyph::draw<closure>
at C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\r
usttype-0.2.1\src\lib.rs:764
10: 0x11cd278 - rusttype::gpu_cache::Cache::cache_queued<closure>
at C:\Users\me\.cargo\registry\src\github.com-1ecc6299db9ec823\r
usttype-0.2.1\src\gpu_cache.rs:426
11: 0x1183961 - foo::font::MyFont::draw_string<glium::Frame>
at D:\projects\foo\src\font.rs:92
12: 0x11d7462 - basic::main
at D:\projects\foo\examples\basic.rs:154
13: 0x13c80fb - __rust_maybe_catch_panic
14: 0x13c3ec0 - std::rt::lang_start::h14cbded5fe3cd915
15: 0x11dd410 - main
16: 0x75c17c03 - BaseThreadInitThunk
17: 0x7758ad1e - RtlInitializeExceptionChain
This is the line where it happens: https://github.com/dylanede/rusttype/blob/master/src/rasterizer.rs#L199 One of the values is NaN for some reason.
Is it possible that rusttype can give an error during loading of the font?