bevyengine / bevyengine/bevy

Bevy UI freezes application after window resize

Open
#16,624 5 comments 1 reaction 0 assignees View on GitHub
A-Text A-UI C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

- 0.15.0

## \[Optional\] Relevant system information

If you cannot get Bevy to build or run on your machine, please include:

```
- cargo 1.83.0 (5ffbef321 2024-10-29)
- MacOS Sonoma 14.1.1 (23B81)
- SystemInfo { os: "MacOS 14.1.1 ", kernel: "23.1.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }
- AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
If your bug is rendering-related, copy the adapter info that appears when you run Bevy.
```

## What you did

I thought I was going crazy... My app just started freezing randomly. It took hours to find why it happens.
So in short I display some messages on screen when events happen. And exactly one message had correct length for BevyUI to go crazy. Changing text size/margins/paddings fixes this bug, so it must be related to screen size.

Code is very simple:
```rust
use bevy::dev_tools::fps_overlay::FpsOverlayPlugin;
use bevy::prelude::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
FpsOverlayPlugin::default(),
))
.add_systems(Startup, spawn_overlay)
.run();
}

fn spawn_overlay(mut commands: Commands) {
let camera_entity = commands.spawn(Camera2d).id();

commands.spawn((
Node {
margin: UiRect::top(Val::VMin(20.0)),
padding: UiRect::all(Val::VMin(1.0)),
..default()
},
TargetCamera(camera_entity),
)).with_child((
Text::new("this is some very weird message that hangs bevy ui when resizing"),
TextFont::default().with_font_size(12.0),
));
}
```

## What went wrong

Application just freezes.
![Image](https://github.com/user-attachments/assets/2ff69de4-c311-416f-b502-da25955e1e99)

Changing text length fixes the problem:
![Image](https://github.com/user-attachments/assets/2f350b00-5ef1-4980-9a2e-4e9f01396ddd)

## Additional information

Here are camera properties before freeze (can't print anything after):
```rust
physical_viewport_size - [2560, 1440]
logical_viewport_size - [1280, 720]
```

Here is a flamegraph:
![Image](https://github.com/user-attachments/assets/4e2f5659-61b9-4397-91e3-13e3057f6859)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.