Skip to content

Bevy UI freezes application after window resize #16624

@MatrixDev

Description

@MatrixDev

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:

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

Changing text length fixes the problem:
Image

Additional information

Here are camera properties before freeze (can't print anything after):

physical_viewport_size - [2560, 1440]
logical_viewport_size - [1280, 720]

Here is a flamegraph:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TextRendering and layout for charactersA-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions