BabylonJS / BabylonJS/BabylonNative
Fix async issues caused by runtime teardown
- Dominant language
- C++
- Stars
- 919
- Forks
- 162
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 19
Description
[Updated by Copilot on behalf of @bghgary]
Async work can outlive the JS object / resource it references when the runtime tears down, causing crashes.
**Prior art:** #1141 ("Fixes for shutting down during async operations") prototyped a general runtime-level fix (`JsRuntimeScheduler::Rundown()` + AppRuntime/WorkQueue across plugins); never landed. See also #1193.
**Two hazard classes (audit):**
- **Graphics** — background threadpool work touching freed bgfx resources. `NativeEngine` is the only such site; stopgap in #1746 (`AsyncTaskTracker` drain in `NativeEngine::Dispose`).
- **JS-env** — async work touching the JS env at teardown with no cancellation. Live instance: `NativeEncoding::EncodeImageAsync` (`cancellation_source::none()`), flagged `// TODO: Crash risk on JS teardown`.
**Follow-up:** a shared teardown-drain primitive covering both classes (promote `AsyncTaskTracker`, or revive a minimal `Rundown`); resolve the NativeEncoding TODO; decide placement — `JsRuntime`/`AppRuntime` (JS-env) vs `DeviceContext` (graphics). Make sure testing is covered.
Contributor guide
Assessment
This issue has not been assessed yet.