bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Bevy UI freezes application after window resize

Open MatrixDev opened this issue 11 months ago • 5 comments

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

MatrixDev avatar Dec 03 '24 10:12 MatrixDev

Could you test with this branch? #15844

rparrett avatar Dec 03 '24 13:12 rparrett

Could you test with this branch? #15844

@rparrett, this bug also reproduces in above PR (I hope revision is correct):

bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "04c190f49bf6e737a67c805cff4e1e2040fd292f" }

MatrixDev avatar Dec 03 '24 13:12 MatrixDev

The correct import should be something like

bevy = { git = "https://github.com/nicoburns/bevy.git", branch = "taffy06" }

But it looks like yours may work well enough to check that this isn't magically fixed in Taffy 0.6.

Thanks for testing.

rparrett avatar Dec 03 '24 13:12 rparrett

@nicoburns this seems like it could be a taffy issue that is not resolved by 0.6.

rparrett avatar Dec 03 '24 13:12 rparrett

@rparrett, I've tested via branch just to be sure and result is the same.

MatrixDev avatar Dec 03 '24 13:12 MatrixDev