Skip to content

Commit 34321d2

Browse files
Emit a warn_once if a font size is larger than 1000 (#22642)
# Objective - Fixes #22625 ## Solution - Add a WARN_FONT_SIZE const and emit a `warn_once` when font size larger than it - Change some `once!(warn!())` to `warn_once!()` ## Testing - Did you test these changes? If so, how? `cargo check`
1 parent e6659b8 commit 34321d2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crates/bevy_text/src/pipeline.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bevy_ecs::{
66
system::ResMut,
77
};
88
use bevy_image::prelude::*;
9-
use bevy_log::{once, warn};
9+
use bevy_log::warn_once;
1010
use bevy_math::{Rect, UVec2, Vec2};
1111
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1212

@@ -166,9 +166,7 @@ impl TextPipeline {
166166
computed.needs_rerender = false;
167167

168168
if scale_factor <= 0.0 {
169-
once!(warn!(
170-
"Text scale factor is <= 0.0. No text will be displayed.",
171-
));
169+
warn_once!("Text scale factor is <= 0.0. No text will be displayed.",);
172170

173171
return Err(TextError::DegenerateScaleFactor);
174172
}
@@ -212,13 +210,24 @@ impl TextPipeline {
212210

213211
// Save spans that aren't zero-sized.
214212
if text_font.font_size <= 0.0 {
215-
once!(warn!(
213+
warn_once!(
216214
"Text span {entity} has a font size <= 0.0. Nothing will be displayed.",
217-
));
215+
);
218216

219217
continue;
220218
}
221219

220+
const WARN_FONT_SIZE: f32 = 1000.0;
221+
if text_font.font_size * scale_factor as f32 > WARN_FONT_SIZE {
222+
warn_once!(
223+
"Text span {entity} has an excessively large font size ({} with scale factor {}). \
224+
Extremely large font sizes will cause performance issues with font atlas \
225+
generation and high memory usage.",
226+
text_font.font_size,
227+
scale_factor,
228+
);
229+
}
230+
222231
let attrs = get_attrs(span_index, text_font, line_height, family, scale_factor);
223232

224233
sections.push((span, attrs));

0 commit comments

Comments
 (0)