blaind / bevy_text_mesh

A bevy 3D text mesh generator for displaying text
MIT License
64 stars 16 forks source link

Panics on mesh generation #35

Open johanhelsing opened 9 months ago

johanhelsing commented 9 months ago

https://github.com/blaind/bevy_text_mesh/blob/677f8f8638a6f5f42982b1dac50fa6c6e01430f5/src/mesh_data_generator.rs#L95

thread 'Compute Task Pool (15)' panicked at C:\Users\Johan\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_text_mesh-0.9.0\src\mesh_data_generator.rs:95:26:
called `Result::unwrap()` on an `Err` value: Glyph2MeshError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_text_mesh::mesh_system::text_mesh`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

I used the bold version of https://fonts.google.com/specimen/Playpen+Sans/about?preview.text=score%201234

    let font = asset_server.load("fonts/playpen_sans_extrabold.ttf#mesh");
    commands.spawn((
        Name::new("ScoreText"),
        TextMeshBundle {
            text_mesh: TextMesh {
                // text: "0".into(), // does not panic
                text: "1".into(), // panics
                style: TextMeshStyle {
                    font: font.clone(),
                    font_size: SizeUnit::NonStandard(36.),
                    color: Color::rgb(0.0, 1.0, 0.0),
                    mesh_quality: Quality::Low,
                    ..default()
                },
                ..default()
            },
            ..default()
        },
    ));
blaind commented 9 months ago

Did this start after 0.9 upgrade? Does it happen at the startup or later?

johanhelsing commented 9 months ago

It happens as i spawn the text. Only tried 0.9

blaind commented 9 months ago

It seems that the root cause is an error with a TTF_ERR_MESHER error code in https://github.com/fetisov/ttf2mesh library. This happens only on some glyphs/characters on the Playpen Sans font (Bold only). For example, characters "1", "5" and "6" and "9" whereas other digit characters work ok.

I implemented a bit better error reporting at https://github.com/blaind/ttf2mesh-rs/pull/16/files but that doesn't really address the cause.

For bevy_text_mesh, I think the .unwrap() / panic at https://github.com/blaind/bevy_text_mesh/blob/main/src/mesh_data_generator.rs#L95 is not a good behavior. Possibly it should fallback with "?" character generated, and if that does not work then having either an empty space or some generic mesh (e.g. a cube)? Any thoughts on this?