BabylonJS / BabylonJS/BabylonNative
Device::UpdateWindow contract is backend-dependent when called while rendering is enabled
- Dominant language
- C++
- Stars
- 919
- Forks
- 162
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 19
Description
`Device::UpdateWindow` silently no-ops on some backends and re-binds on others when called while `Bgfx.Initialized == true`. No error, no log. Asymmetric with #1689 (which made `UpdateDevice` throw — clean because `UpdateDevice` is uniformly init-only on every backend).
### Mechanics
`Update*` methods set `Dirty` on `Bgfx.InitState`. Each frame, `DeviceImpl::Frame() → UpdateBgfxState()` runs `bgfx::setPlatformData + bgfx::frame(BGFX_FRAME_DISCARD) + bgfx::reset` when dirty. The new `nwh` reaches `g_platformData`; whether bgfx re-binds the swap chain / surface is backend-specific:
| Backend | Re-binds to new `nwh`? |
|---|---|
| OpenGL / Android | Yes (`GlContext::resize` recreates EGL surface from `g_platformData.nwh`) |
| OpenGL / Emscripten | Yes (canvas resize) |
| OpenGL / Linux Wayland | Resizes existing window only |
| OpenGL / Linux X11 (GLX) | No |
| D3D11 / Win32 | No (swap chain bound to original HWND at init) |
| D3D11 / UWP SwapChainPanel | Yes, when `m_scd.ndt == SwapChainPanel marker` |
| D3D12 | No |
| Metal | Only when `BGFX_RESET_INTERNAL_FORCE` is set (external callers don''t set this) |
### Where it matters
`Apps/Playground/Android/.../BabylonNativeJNI.cpp` `surfaceChanged` calls `UpdateWindow + UpdateSize` mid-render. Works only because Android-OpenGL re-binds. Same pattern on Win32 D3D11/D3D12, iOS Metal, or Linux X11 would silently keep rendering to the old window.
### Options
1. **Throw from `UpdateWindow` when initialized** (symmetric with #1689). Callers do `Disable → UpdateWindow → UpdateSize → Enable`. Android JNI path needs updating; small efficiency regression vs EGL surface re-create.
2. **Wait for uniform `nwh` re-bind in bgfx reset**, then keep `UpdateWindow` reset-applicable everywhere. Depends on bgfx changes that don''t exist yet.
Contributor guide
Assessment
This issue has not been assessed yet.