From 0a8e2a3c9d53f12d66c833a82a15580dcd0f859d Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 26 Nov 2024 19:28:43 -0800 Subject: [PATCH] Skip empty spans when updating text buffers (#16524) # Objective Fixes #16521 ## Solution If an empty span is encountered (such as the default `Text` value), we skip it entirely when updating buffers. This prevents unnecessarily bailing when the font doesn't exist (ex: when the default font is disabled) --- crates/bevy_text/src/pipeline.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 92b5cd902e814..f8e7274ef31f2 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -107,6 +107,12 @@ impl TextPipeline { computed.entities.clear(); for (span_index, (entity, depth, span, text_font, color)) in text_spans.enumerate() { + // Save this span entity in the computed text block. + computed.entities.push(TextEntity { entity, depth }); + + if span.is_empty() { + continue; + } // Return early if a font is not loaded yet. if !fonts.contains(text_font.font.id()) { spans.clear(); @@ -122,9 +128,6 @@ impl TextPipeline { return Err(TextError::NoSuchFont); } - // Save this span entity in the computed text block. - computed.entities.push(TextEntity { entity, depth }); - // Get max font size for use in cosmic Metrics. font_size = font_size.max(text_font.font_size);