Commit 9e8ab8b
Throw from Device::UpdateDevice when called while rendering is enabled
Before this change, UpdateDevice's effect on a Device whose bgfx is already
initialized was silently buffered: the new device pointer was stored in
Bgfx.InitState.platformData, but bgfx::init does not run again until the
caller does a DisableRendering / EnableRendering cycle, and EnableRendering
early-outs while already initialized. The result was a swap that appeared to
succeed but in which the device never actually changed -- a footgun that's
hard to diagnose.
This commit:
- Throws std::runtime_error from DeviceImpl::UpdateDevice when called with
Bgfx.Initialized == true. The throw message names the required call
sequence (DisableRendering first).
- Documents the contract on the public Device::UpdateDevice declaration in
Device.h, including the canonical D3D11/D3D12 device-removed recovery
sequence.
- Adds TEST(Device, UpdateDeviceThrowsWhenRenderingEnabled) that exercises
the contract: pre-init UpdateDevice is permitted, post-init throws,
and the swap completes successfully after DisableRendering.
UpdateWindow has the same surface-level contract but is left unchanged in
this PR -- the Android Playground's surfaceChanged JNI callback calls
UpdateWindow followed by UpdateSize while bgfx is initialized, and on the
OpenGL backend bgfx::reset (triggered by UpdateSize) re-creates the EGL
surface from the new ANativeWindow*. So the "init-only vs. reset-applicable"
classification is more nuanced for UpdateWindow than for UpdateDevice, and
narrowing the change to UpdateDevice avoids breaking the Android flow.
UpdateBackBuffer, UpdateSize, UpdateMSAA, and UpdateAlphaPremultiplied are
left unchanged because they are reset-applicable: bgfx::reset (called from
UpdateSize) reads g_platformData.backBuffer and init.resolution.reset, so
those updates take effect mid-frame as expected. The existing
TEST(Device, BackBuffer) exercises that flow and continues to pass.
Local verification: full UnitTests suite on Win32 D3D11 PASSED including
the new test; Win32 D3D12 builds and runs (UniformPadding sample passes).
[Created by Copilot on behalf of @bghgary]
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 58f8f14 commit 9e8ab8b
3 files changed
Lines changed: 66 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
115 | 130 | | |
| 131 | + | |
116 | 132 | | |
117 | 133 | | |
118 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
0 commit comments