From 784a9d36bda7db14e1faced16d8f848d9b1d5158 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Wed, 22 Jan 2025 18:43:59 -0800 Subject: [PATCH] Add warning for font sizes `<= 0.0` (#17501) # Objective Alternative to #9660, which is outdated since "required components" landed. Fixes #9655 ## Solution This is a different approach than the linked PR, slotting the warning into an existing check for zero or negative font sizes in the text pipeline. ## Testing Replaced a font size with `0.0` in `examples/ui/text.rs`. ``` 2025-01-22T23:26:08.239688Z INFO bevy_winit::system: Creating new window App (0v1) 2025-01-22T23:26:08.617505Z WARN bevy_text::pipeline: Text span 10v1 has a font size <= 0.0. Nothing will be displayed. ``` --- crates/bevy_text/Cargo.toml | 1 + crates/bevy_text/src/pipeline.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/crates/bevy_text/Cargo.toml b/crates/bevy_text/Cargo.toml index dd4ed912a6..3ad3ef9557 100644 --- a/crates/bevy_text/Cargo.toml +++ b/crates/bevy_text/Cargo.toml @@ -19,6 +19,7 @@ bevy_color = { path = "../bevy_color", version = "0.16.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev" } bevy_image = { path = "../bevy_image", version = "0.16.0-dev" } +bevy_log = { path = "../bevy_log", version = "0.16.0-dev" } bevy_math = { path = "../bevy_math", version = "0.16.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [ "bevy", diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 9ab627b562..ef1f0e42ba 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -8,6 +8,7 @@ use bevy_ecs::{ system::ResMut, }; use bevy_image::prelude::*; +use bevy_log::{once, warn}; use bevy_math::{UVec2, Vec2}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_utils::HashMap; @@ -139,6 +140,10 @@ impl TextPipeline { // Save spans that aren't zero-sized. if scale_factor <= 0.0 || text_font.font_size <= 0.0 { + once!(warn!( + "Text span {entity} has a font size <= 0.0. Nothing will be displayed.", + )); + continue; } spans.push((span_index, span, text_font, face_info, color));