BabylonJS / BabylonJS/BabylonNative

Fix async issues caused by runtime teardown

Open
#1,420 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.