Skip to content

Text with an invalid span is silently not rendered #18205

Open
@benfrankel

Description

@benfrankel

Bevy version

main (0.16.0-dev)

What you did

commands.spawn((
    Text::new("Hello, "),
    TextFont::from_font(font_a),
)).with_child(
    TextSpan::new("World!"),
    TextFont::from_font(font_b),
)).with_child(TextSpan::new(" :)"));

What went wrong

When one of font_a or font_b is not a valid handle to a font (e.g. if the asset is still loading, or if Handle::default() is used while bevy's default font feature is disabled), the entire text will be invisible with no warning emitted. It can be difficult to trace down why the text isn't rendering, because it looks like the issue is "higher up" than it actually is, and you'd need good tooling for inspecting entities and font handles.

Suggestions:

  1. Log a warning like "text span {id} is using an invalid font handle {handle}, so the entire text cannot be rendered".
  2. Render the rest of the text, skipping only the invalid spans.
  3. Render the rest of the text, replacing invalid spans with � or similar.
  4. Suggestion (2) or (3) but also log a warning.

Personal preference towards 2 or 4, but 1 is good enough.

Additional information

A similar issue can happen when setting a font size of f32::NAN, but the effects of doing so are inconsistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TextRendering and layout for charactersC-BugAn unexpected or incorrect behaviorC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions