Skip to content
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

UI scaling example crashes #6466

Closed
darthdeus opened this issue Nov 4, 2022 · 3 comments
Closed

UI scaling example crashes #6466

darthdeus opened this issue Nov 4, 2022 · 3 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@darthdeus
Copy link
Contributor

Bevy version

3a14ae4

What you did

  • Run cargo run --example ui_scaling
  • Press up arrow to scale up the UI
  • Press down arrow to scale it back down, immediate crash here

Pressing down first and up second also crashes

What went wrong

thread 'main' panicked at 'Fatal error when processing text: exceeded 16 available TextAltases for font. This can be caused by using an excessive number of font sizes. If you are changing font sizes dynamically consider using Transform::scale to modify the size. If you need more font sizes modify TextSettings.max_font_atlases..', crates/bevy_ui/src/widget/text.rs:138:21
@darthdeus darthdeus added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 4, 2022
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Nov 4, 2022
@alice-i-cecile
Copy link
Member

Broken by #5708, ping @xtr3m3nerd :)

@xtr3m3nerd
Copy link
Contributor

So this here is an example of what would have caused a memory leak before, which is what the error introduced in my change is intending to protect against. This is happening because the scale_factor in pipeline.queue_text (which is what the UiScale resource modifies) will modify the the font_size, ultimately growing the FontAtlasSet. In this example the scale is being modified dynamically on a frame by frame basis, which I cant imaging is a typical usecase for UiScale, which I see as primarily being used for setting up UI based on screen and game settings.

Now considering this usecase and wanting to demonstrate dynamically changing the UI the example can easily be fixed by adding:

.insert_resource(TextSettings { allow_dynamic_font_size: true, ..default() })

to the example.

In this situation the panic error text in the #5708 fix seems confusing. I was thinking that we should modify it to also mention that dynamically modifying the scale could also be the cause of the issue.

@alice-i-cecile alice-i-cecile added the C-Examples An addition or correction to our examples label Nov 4, 2022
@alice-i-cecile
Copy link
Member

Great analysis. I think we should improve the error message, and fix the example by configuring that resource.

@alice-i-cecile alice-i-cecile added the D-Trivial Nice and easy! A great choice to get started with Bevy label Nov 4, 2022
@bors bors bot closed this as completed in 40ea5b4 Nov 5, 2022
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes: bevyengine#6466 
Summary: The UI Scaling example dynamically scales the UI which will dynamically allocate fonts to the font atlas surpassing the protective limit, throwing a panic. 

## Solution

- Set TextSettings.allow_dynamic_font_size = true for the UI Scaling example. This is the ideal solution since the dynamic changes to the UI are not continuous yet still discrete.
- Update the panic text to reflect ui scaling as a potential cause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants