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

available_size of context and ui are too large #5703

Open
ranjeethmahankali opened this issue Feb 10, 2025 · 0 comments
Open

available_size of context and ui are too large #5703

ranjeethmahankali opened this issue Feb 10, 2025 · 0 comments
Labels
bug Something is broken

Comments

@ranjeethmahankali
Copy link

ranjeethmahankali commented Feb 10, 2025

Describe the bug
ui.available_size(), ctx.screen_rect() and several other properties report arbitrarily large, yet finite numbers for the first one or two frames after starting the native application. I have an image viewer that uses the available size to decide how many images to load from disk. This causes the app to try and load an unreasonably large number of images from the disk, and crash by trying to allocate too much memory.

I had been using the 0.28.1 version for a while, without this issue. I ran into the issue when I tried to update to 0.31.0 to try out the Scene feature.

To Reproduce
Steps to reproduce the behavior:

  1. Start a native eframe.
  2. Inside the update, in the eframe::App trait implementation, create a panel, and print ui.available_size(). This should be a number much larger than the screen.
  3. Using .with_clamp_size_to_monitor_size(true) with the ViewportBuilder doesn't fix the problem either.

Expected behavior
Either the available space is clamped to the screen size, or if egui needs a couple of frames to calculate the available size, it would be nice to have a way to ask if things are ready, i.e. if the reported size is actually valid.

Screenshots
In the snippet below, render_grid_preview tries to estimate the files that need to be read and rendered.

        // Files previews.
        egui::CentralPanel::default().show(ctx, |ui| {
            if _frame.info().cpu_usage.is_some() {
                self.render_grid_preview(ui);
            } else {
                dbg!(ui.available_size());
                dbg!(ctx.screen_rect());
            }
        });

For the first 1 or two frames, control flow goes into the else branch and prints the following:

[src/gui.rs:357:17] ui.available_size() = [8121.5 8273.3]
[src/gui.rs:358:17] ctx.screen_rect() = [[0.0 0.0] - [8333.3 8333.3]]

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version 0.31.0

Additional context
I am currently checking whether the frame is ready with proper sizes, by checking frame.info().cpu_usage.is_some(). But I am not sure if this makes any sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant