Commit 28840fb
committed
fix: size backbuffer readbacks from the backbuffer, not the viewport
Resizing the window during startup aborted the game:
terminate called after throwing an instance of 'std::runtime_error'
what(): GetBackBufferData: data array too small for requested region
GetBackBufferData()'s no-rect overload reads the WHOLE backbuffer, and CNA
validates the array against PresentationParameters.BackBufferWidth/Height.
All three one-shot captures here sized their arrays from Viewport instead.
Those are not the same rectangle. EasyGL runs a FixedHeightDynamicWidth
virtual resolution, so on a resize the Viewport becomes the logical size --
height pinned to the virtual 480, width following the window's aspect -- while
the backbuffer stays at 800x480. Confirmed live with CNA_BACKBUFFER_READ_TRACE:
after a resize, backbuffer=800x480 viewport=802x480. Widen the window and the
array is merely oversized; make it narrower than 800:480 and it is too small,
and the uncaught std::runtime_error is a hard SIGABRT.
The terrain diagnostic had a second instance of the same mistake: its 5x5
grid of single-pixel sample rectangles was also derived from the Viewport, and
CNA bounds-checks those against the backbuffer too, so a Viewport wider than
the backbuffer threw std::out_of_range from a different line.
Ask for the backbuffer's own size through a small shared helper, which is what
these calls actually read. elementCount is then always exactly
backBufferWidth * backBufferHeight -- the quantity CNA compares against -- so
the mismatch is unreachable by construction rather than merely unlikely.
The engine side of the resize story (EasyGL applying the logical size as the
physical GL viewport, and an SDL3 window-sync timeout thrown as a fatal
exception) was fixed separately in CNA and is not this commit's subject.1 parent c32bc8f commit 28840fb
1 file changed
Lines changed: 34 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
275 | 298 | | |
276 | 299 | | |
277 | 300 | | |
| |||
3661 | 3684 | | |
3662 | 3685 | | |
3663 | 3686 | | |
3664 | | - | |
3665 | | - | |
3666 | | - | |
| 3687 | + | |
| 3688 | + | |
| 3689 | + | |
| 3690 | + | |
| 3691 | + | |
| 3692 | + | |
| 3693 | + | |
3667 | 3694 | | |
3668 | 3695 | | |
3669 | 3696 | | |
| |||
4182 | 4209 | | |
4183 | 4210 | | |
4184 | 4211 | | |
4185 | | - | |
4186 | | - | |
4187 | | - | |
| 4212 | + | |
| 4213 | + | |
4188 | 4214 | | |
4189 | 4215 | | |
4190 | 4216 | | |
| |||
4207 | 4233 | | |
4208 | 4234 | | |
4209 | 4235 | | |
4210 | | - | |
4211 | | - | |
4212 | | - | |
| 4236 | + | |
| 4237 | + | |
4213 | 4238 | | |
4214 | 4239 | | |
4215 | 4240 | | |
| |||
0 commit comments