slint icon indicating copy to clipboard operation
slint copied to clipboard

Slint panics on linux when no fonts is found

Open efancier-cn opened this issue 1 year ago • 6 comments

On a ARM Contex-A7 Linux platform, able to cross-compile the slint-test code, execute it, got following message:

thread 'main' panicked at 'removal index (is 0) should be < len (is 0)', /home/roli/.cargo/registry/src/github.com-1ecc6299db9ec823/i-slint-renderer-femtovg-1.0.0/fonts.rs:240:54 stack backtrace: 0: rust_begin_unwind at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5 1: core::panicking::panic_fmt at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14 2: alloc::vec::Vec<T,A>::remove::assert_failed at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/vec/mod.rs:1513:13 3: <i_slint_renderer_femtovg::fonts::FontCache as core::default::Default>::default 4: std::thread::local::fast::Key<T>::try_initialize 5: std::thread::local::LocalKey<T>::with 6: i_slint_renderer_femtovg::fonts::text_size 7: <i_slint_renderer_femtovg::FemtoVGRenderer as i_slint_core::renderer::Renderer>::text_size 8: <i_slint_backend_winit::renderer::femtovg::GlutinFemtoVGRenderer as i_slint_core::renderer::Renderer>::text_size 9: <i_slint_core::items::text::Text as i_slint_core::items::Item_vtable_mod::Item>::layout_info::{{closure}} 10: <i_slint_core::items::text::Text as i_slint_core::items::Item_vtable_mod::Item>::layout_info 11: core::ops::function::FnOnce::call_once 12: i_slint_core::properties::alloc_binding_holder::evaluate 13: i_slint_core::properties::Property<T>::get 14: core::ops::function::FnOnce::call_once 15: i_slint_core::properties::alloc_binding_holder::evaluate 16: i_slint_core::properties::Property<T>::get 17: <slint_test::slint_generatedAppWindow::InnerAppWindow as const_field_offset::PinnedDrop>::drop::VT::layout_info 18: i_slint_core::component::Component_vtable_mod::ComponentTO::layout_info 19: <i_slint_backend_winit::glwindow::GLWindow<Renderer> as i_slint_core::window::WindowAdapterSealed>::show 20: i_slint_core::window::WindowInner::show 21: i_slint_core::api::Window::show 22: <slint_test::slint_generatedAppWindow::AppWindow as i_slint_core::api::ComponentHandle>::run 23: slint_test::main

efancier-cn avatar Apr 14 '23 15:04 efancier-cn

It looks like your target platform is missing some basic fonts. When running fc-match sans-serif on the target, the command should print the name of a .ttf file that's to be used as default font. Could it be that you're missing some font packages? (Noto?)

tronical avatar Apr 14 '23 15:04 tronical

Marking this as bug in any case. If we continue to panic, then the panic message needs to be about the fact that we couldn't locate any fonts. Otherwise I guess... we should not render any text simply? (this happens during text rendering).

@ogoffart any preference here? (panic vs. no-rendering-and-stderr-message)

tronical avatar Apr 14 '23 15:04 tronical

@ogoffart any preference here? (panic vs. no-rendering-and-stderr-message)

I'm going to say no-rendering-and-stderr-message. Panic is the absolute worst. But stderr messages isn't great either.
Would be great to have a way to report non-fatal error messages from the API.

We could also chose to make it a fatal error and end up in a slint::PlatformError. No text is quite bad after all.

But my guts tell me that a "WARNING: Could not load default font. See https://github.com/slint-ui/slint/issues/xyz¹ for troubleshooting. {}" error message in the console would be alright I think.

¹ or dicsussion?, or .md file in the docs folder? or something in our docs?

ogoffart avatar Apr 14 '23 16:04 ogoffart

@tronical , The system is generated by buildroot, it is possible that the font is missing, I will check. is it possible to put a fallback font rather than panic or stderr

efancier-cn avatar Apr 14 '23 19:04 efancier-cn

@tronical , The system is generated by buildroot, it is possible that the font is missing, I will check. is it possible to put a fallback font rather than panic or stderr

I think this panic occurs when there is no fallback font available on the system.

tronical avatar Apr 15 '23 08:04 tronical

To clarify: The acceptance criteria here is to not panic when running on a (linux) system where we can't find fonts, but instead print a message to stderr and not render any text.

tronical avatar Feb 06 '24 13:02 tronical