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

Web canvas size is tiny for the first frame #4622

Closed
emilk opened this issue Jun 5, 2024 · 1 comment · Fixed by #4628
Closed

Web canvas size is tiny for the first frame #4622

emilk opened this issue Jun 5, 2024 · 1 comment · Fixed by #4628
Labels
bug Something is broken eframe Relates to epi and eframe web Related to running Egui on the web

Comments

@emilk
Copy link
Owner

emilk commented Jun 5, 2024

Repro

--- a/crates/eframe/src/web/app_runner.rs
+++ b/crates/eframe/src/web/app_runner.rs
@@ -188,6 +188,7 @@ impl AppRunner {
     /// The result can be painted later with a call to [`Self::run_and_paint`] or [`Self::paint`].
     pub fn logic(&mut self) {
         let canvas_size = super::canvas_size_in_points(self.canvas(), self.egui_ctx());
+        log::info!("canvas_size: {canvas_size:?}");
         let raw_input = self.input.new_frame(canvas_size);
 
         let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
./scripts/build_demo_web.sh && ./scripts/start_server.sh

Result

image

The symptom is that all windows gets squashed to a very small size, and pushed to the top left corner:

image

@emilk emilk added bug Something is broken web Related to running Egui on the web eframe Relates to epi and eframe labels Jun 5, 2024
@emilk emilk added this to the Next Major Release milestone Jun 5, 2024
@jprochazk
Copy link
Collaborator

This is caused by the first requestAnimationFrame firing the callback before the resize observer is run on observe. Both are asynchronous and it seems like the animation frame takes precedence in the event loop because it is registered first... Or something like that.

Because the resize observer is called not just on every resize but also on the call to observe (exactly for the purpose of determining the initial dimensions), we can move the first request_animation_frame from WebRunner::start to the resize observer callback.

emilk pushed a commit that referenced this issue Jun 6, 2024
This PR ensures the first animation frame happens _after_ the resize
observer has had a chance to do its job.

* Closes #4622

The first commit contains some `log` calls to observe the changed
behavior:

Before:
```
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [300.0 150.0]
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```

After:
```
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken eframe Relates to epi and eframe web Related to running Egui on the web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants