-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update_text2d_layout
creates new font atlases when the primary window is closed
#7849
base: main
Are you sure you want to change the base?
Conversation
update_text2d_layout
creates new font atlases when the window closedupdate_text2d_layout
creates new font atlases when the primary window is closed
The UI has the same problem, but it might be more complicated and I need to test some things so there will be a separate PR. |
I forgot all about this bug. This fix makes sense to me, but I'd like to follow up after #9676 is resolved. |
@ickshonpe can you rebase this? |
Yep going to concentrate on all my old PRs the next couple of days and get them merged or closed. |
Rebased. The warning has been removed but the bug is still there and this fix still works. |
Looking at this again, and maybe it's not correct to skip text when there's no window? This would break text for headless rendering scenarios, right? Maybe instead the scale factor could first fall back to the previous scale factor before falling back to Something like this? Expand Diffdiff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs
index 893f127b8..28688591e 100644
--- a/crates/bevy_text/src/text2d.rs
+++ b/crates/bevy_text/src/text2d.rs
@@ -223,7 +223,7 @@ pub fn extract_text2d_sprite(
/// It does not modify or observe existing ones.
#[allow(clippy::too_many_arguments)]
pub fn update_text2d_layout(
- mut last_scale_factor: Local<f32>,
+ mut last_scale_factor: Local<Option<f32>>,
// Text items which should be reprocessed again, generally when the font hasn't loaded yet.
mut queue: Local<EntityHashSet>,
mut textures: ResMut<Assets<Image>>,
@@ -246,13 +246,15 @@ pub fn update_text2d_layout(
// TODO: Support window-independent scaling: https://github.com/bevyengine/bevy/issues/5621
let scale_factor = windows
.get_single()
+ .ok()
.map(|window| window.resolution.scale_factor())
+ .or_else(|| *last_scale_factor)
.unwrap_or(1.0);
let inverse_scale_factor = scale_factor.recip();
- let factor_changed = *last_scale_factor != scale_factor;
- *last_scale_factor = scale_factor;
+ let factor_changed = *last_scale_factor != Some(scale_factor);
+ *last_scale_factor = Some(scale_factor); |
4b4ff0f
to
428bd02
Compare
Yep that's definitely an improvement. I think Text2d is a bit broken though anyway for anything not the primary window. It looks like it will be really annoying to get it to work properly like storing multiple versions of each font and computing multiple different text layouts for each render target with a different scale factor. |
Objective
Necessary conditions:
Then when
update_text2d_layout
runs, it finds no primary window and assumes a scale factor of 1.The previous scale_factor was not equal to 1 and the text pipeline's old font atlases were created for a non-1 scale factor, so it creates new font atlases even though the app is closing.
The bug was first identified in #6666
Minimal Example
Output
On closing the window you'll see the warning (if you don't, increase the number of text sections):
The app should only create font atlases on startup, but it doesn't display this warning until after you close the window
Solution
Skip
update_text_layout
when there is no primary window.Changelog
update_text2d_layout
.Local
flagskipped
toupdate_text2d_layout
. This should ensure there are no edge cases where text might not get drawn at all.