Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX#1703
Conversation
…tubs
The OpenGL backend's ExternalTexture::Impl methods (GetInfo, Set, Get)
unconditionally threw std::runtime_error{"not implemented"}, but these
methods are called unconditionally from the dispatch code in
ExternalTexture_Shared.h (included after the class definition).
MSVC's flow analysis inlined the throw and flagged the post-call code
as unreachable, producing C4702 errors under /WX on the
OpenGLWindowsDevOnly build configuration.
A previous change (BabylonJS#1695) masked the warning with a
`target_compile_options(ExternalTexture PRIVATE /wd4702)` gated on
GRAPHICS_API=OpenGL+MSVC. This silenced the diagnostic but hid any
other legitimate C4702 introduced in the same translation unit going
forward.
Attempts to fix this via `[[noreturn]]` on the stub methods made things
worse - MSVC propagated the "never returns" attribute through the
dispatch code, flagging MORE post-call statements as unreachable.
This change instead replaces the throw-stubs with inert no-op stubs
that return default-constructed values. The dispatch code in
ExternalTexture_Shared.h now sees the calls as returning normally,
which eliminates the unreachable-code paths entirely. The /wd4702
workaround in CMakeLists.txt is removed.
Functional impact: Calling an ExternalTexture API on the OpenGL backend
(which is not shipped, only used for the OpenGLWindowsDevOnly developer
build) now yields an inert/null texture rather than a thrown exception.
The OpenGL backend has never supported ExternalTexture, no tests
exercise it on OpenGL, and the Playground does not use it - so this
behavioural change has no test impact.
Verified clean build under Debug + Release + RelWithDebInfo of
ExternalTexture, full Playground build under OpenGL and D3D11
backends. Smoke test passes on D3D11 Release.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Replaces unimplemented throw stubs in the OpenGL ExternalTexture backend with default-value returns to silence MSVC C4702 (unreachable code) warnings under /WX, and removes the corresponding /wd4702 workaround.
Changes:
- Replace
throw std::runtime_error{"not implemented"}with default returns / empty bodies inExternalTexture_OpenGL.cpp. - Remove the OpenGL+MSVC-specific
/wd4702compile option fromCMakeLists.txt. - Add an explanatory comment describing the rationale for the stub behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp | Convert throwing stubs into inert default-returning stubs and add an explanatory comment. |
| Plugins/ExternalTexture/CMakeLists.txt | Remove the now-unneeded /wd4702 MSVC workaround for the OpenGL build. |
| return Graphics::TextureT{}; | ||
| } | ||
|
|
||
| private: | ||
| static void GetInfo(Graphics::TextureT, std::optional<Graphics::TextureFormatT>, Info&) | ||
| { | ||
| throw std::runtime_error{"not implemented"}; | ||
| } | ||
|
|
||
| void Set(Graphics::TextureT) | ||
| { | ||
| throw std::runtime_error{"not implemented"}; | ||
| } |
There was a problem hiding this comment.
Addressed by 834c99f: the throws are restored, so observable behavior matches the original "not implemented" exception path. The only thing that changes is how MSVC's C4702 is silenced (local pragma in this TU instead of returning early).
| // The OpenGL backend does not implement ExternalTexture. The Impl methods | ||
| // below return default-constructed values rather than throwing so that the | ||
| // shared dispatchers in ExternalTexture_Shared.h (which is included after | ||
| // this class definition) don't produce unreachable-code paths that MSVC | ||
| // flags as C4702 under /WX. Any caller that actually invokes an | ||
| // ExternalTexture API on OpenGL will receive an inert/null texture and | ||
| // get a graphics-level error downstream. |
There was a problem hiding this comment.
Addressed by 834c99f: kept the throw and silenced C4702 locally with #pragma warning(push)/disable: 4702/pop around the ExternalTexture_Shared.h include. The rationale (and why [[noreturn]] / inert-return alternatives were rejected) is in the block comment at the top of the file.
…agma
Per code review: working around a compiler warning by changing runtime
behavior is undesirable. Restore the original "not implemented" throws
in the OpenGL backend's ExternalTexture stubs and instead suppress
C4702 only around the #include of ExternalTexture_Shared.h, which is
where the unreachable-code paths are instantiated.
Compared to the previous approach (returning default-constructed values
from the stubs):
- Callers now get a clear "not implemented" diagnostic identical to
every other unimplemented backend path, instead of silently
receiving a null texture.
- The warning suppression is scoped to a few lines of source rather
than the entire translation unit, so future legitimate C4702 in
this file still surfaces under /WX.
Compared to the original TU-wide /wd4702 in CMakeLists.txt (PR BabylonJS#1695):
- Still removes the CMake-level workaround.
- Suppression is now visible at the source site that triggers it,
with comment explaining the rationale and the alternatives that
were rejected ([[noreturn]] propagating through the shared
dispatcher; replacing throws with inert returns changing product
behavior).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1d286ee to
834c99f
Compare
ryantrem
left a comment
There was a problem hiding this comment.
The PR description seems out of date with the changes. Is it just moving the warning suppression into the code to make it more restrictive (only part of the file, not the whole file)?
| // - Replacing the throws with inert return-default stubs: changes | ||
| // product behaviour (callers would silently receive a null texture | ||
| // instead of a clear "not implemented" error) to work around a | ||
| // compiler warning. Rejected on principle. |
There was a problem hiding this comment.
This comment block is PR rationale (alternatives considered, why they were rejected) — that belongs in the PR description, not in the source. A future reader just needs to know why the pragma exists. Something like "Suppress C4702 for the shared dispatcher — Impl stubs always throw, making post-call code unreachable" is enough.
Per-test PIL-composite triage of all 17 ``subtle pixel-diff`` tests. None of them are deterministic-cosmetic (no re-bakes possible - all show real visible regressions). Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 17 tests with accurate symptom descriptions, classifying into recurring root-cause clusters: - 9 GUI green->red color regressions (idx 160, 174, 175, 196, 197, 370, 402, 566, 587) - 4 OpenPBR analytic-lights right-column red rendering (580, 584, 587, 592) - 1 instanced billboard foliage red (169) - 1 LineEdgesRenderer extra red lines (179) - 1 Background blur red splotches (602) - 1 Clip planes GUI sliders red (182) - 1 Instanced Bones edge-AA (256, borderline) **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
Per-test triage of 5 post-#1695 pixel-diff fallouts. Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 3 entries to name the real BN rendering regression instead of generic "Pixel comparison fails": - idx 363 SSR2 - SSR not rendering wet floor. - idx 369 Sprites Pixel Perfect - sprite alpha-blending broken. - idx 395 soft-transparent-shadows - soft-shadow filter precision degraded. **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes for follow-up engineering work. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
Replaces
throw "not implemented"stubs inPlugins/ExternalTexture/Source/ExternalTexture_OpenGL.cppwith inert default-value returns. The dispatcher inExternalTexture_Shared.hno longer trips MSVC C4702 (unreachable code) under/WX, so the/wd4702workaround can be removed fromPlugins/ExternalTexture/CMakeLists.txt.Changes:
Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp- stubs return default-constructed values.Plugins/ExternalTexture/CMakeLists.txt- drop/wd4702.Verified: clean under Debug + Release + RelWithDebInfo on OpenGL and D3D11.
Landing context
This PR is one of 7 splits from the proven CI-green combined preview in draft PR #1702 (see #1702 for the full intended end-state and verified CI run 26044922430).
Recommended landing order
Tier 1 - parallel-reviewable, no source conflicts:
reasonrewrites (5 entries)reasonrewrites (17 entries)Tier 2 - sequential, each touches
Apps/Playground/CMakeLists.txtSCRIPTS list +Apps/Playground/Shared/AppContext.cppLoadScript order; rebase the next branch after the previous merges:Reference policy reminder
Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: 0 PNGs.