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

Fix crash on request_animation_frame when destroying web runner #4169

Merged
merged 4 commits into from Mar 14, 2024

Conversation

jprochazk
Copy link
Collaborator

Previously, any frames in flight (requestAnimationFrame) on web were not being cancelled (cancelAnimationFrame) when WebRunner::destroy was called. If a user called destroy, then immediately removed the canvas from the DOM, eframe could panic with a "failed to find (canvas) element by id" error message.

This PR changes two things:

  • The canvas element is directly referenced everywhere it's needed instead of being looked up by canvas_id1
  • The RAF handle is stored in WebRunner and cancelAnimationFrame is called on it inside of WebRunner::destroy2

Footnotes

  1. The WebGL/WGPU backends were already holding onto the canvas (and associated GPU context), so the change is just converting all the get_element_by_id lookups to retrieve the canvas from the web runner handle.

  2. There is only ever one frame in flight, so we store it directly as a scalar field.

@jprochazk jprochazk added the web Related to running Egui on the web label Mar 13, 2024
@jprochazk jprochazk added the eframe Relates to epi and eframe label Mar 13, 2024
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer ⭐

crates/eframe/src/web/web_painter_glow.rs Outdated Show resolved Hide resolved
crates/eframe/src/web/web_runner.rs Outdated Show resolved Hide resolved
crates/eframe/src/web/web_runner.rs Outdated Show resolved Hide resolved
@emilk emilk changed the title Fix RAF/Canvas handling Fix crash on request_animation_frame when destroying web runner Mar 14, 2024
@emilk emilk merged commit c5eaba4 into master Mar 14, 2024
35 checks passed
@emilk emilk deleted the jan/fix-raf-and-canvas-handling branch March 14, 2024 09:26
emilk pushed a commit to rerun-io/rerun that referenced this pull request Mar 17, 2024
Snippets™️ (formerly known as "code examples" or "doc examples") are now
built on CI together with Examples™️, and uploaded to the same place.

Also includes some changes to example screenshots (adding
`data-inline-viewer` attributes), and updating the egui rev to fix a bug

- Blocked by emilk/egui#4169

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5438/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5438/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5438/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5438)
- [Docs
preview](https://rerun.io/preview/27f898acc6efda581ce2a4f540f73dc68ef50578/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/27f898acc6efda581ce2a4f540f73dc68ef50578/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe web Related to running Egui on the web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants