Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX#1703
Merged
bkaradzic-microsoft merged 3 commits intoMay 28, 2026
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.
This was referenced May 18, 2026
Contributor
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. |
…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
reviewed
May 18, 2026
Member
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)?
bghgary
approved these changes
May 21, 2026
bkaradzic-microsoft
added a commit
that referenced
this pull request
May 21, 2026
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**.
bkaradzic-microsoft
added a commit
that referenced
this pull request
May 21, 2026
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**.
Per BabylonJS#1703 (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. Collapse the 20-line block in Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp down to the two-line summary bghgary suggested. The alternatives-considered detail (noreturn, TU-wide /wd4702, inert return-default stubs) is moved into the PR description where future reviewers can find it without weighing down the source. No behaviour change. ExternalTexture builds clean on win32-gl (OpenGLWindowsDevOnly RelWithDebInfo) - the C4702 suppression around the ExternalTexture_Shared.h include is still in place and effective. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes MSVC C4702 (unreachable code) under
/WXinPlugins/ExternalTexture/Source/ExternalTexture_OpenGL.cppso the OpenGL TU builds cleanly without the project-wide/wd4702workaround.What changed
Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cppkeeps the unimplementedImplstubs asthrow std::runtime_error{"not implemented"}(so callers get an unambiguous diagnostic matching every other backend's unimplemented path) and wraps the#include "ExternalTexture_Shared.h"line in#pragma warning(push)/(disable: 4702)/(pop). The shared dispatchers instantiated by that include unconditionally call the stubs, so MSVC's flow analysis flags the dispatcher's post-call code as unreachable; the pragma suppresses C4702 only for the dispatcher code instantiated in this translation unit. Any other code in this file is still subject to/WXC4702 enforcement.Plugins/ExternalTexture/CMakeLists.txt- drop the/wd4702target compile option, which previously silenced C4702 across the whole target.Alternatives considered
[[noreturn]]on the stubs: MSVC propagates "never returns" through the shared dispatcher, which flags more post-call statements as unreachable. Tried and rejected (it made the warning worse)./wd4702viatarget_compile_options: silences any future legitimate C4702 elsewhere in the same TU, defeating/WX. The current localized#pragma warning(push/pop)block keeps the rest of the TU under/WXenforcement.Verified
Clean under Debug + Release + RelWithDebInfo on OpenGL (
win32-gl,GRAPHICS_API=OpenGLWindowsDevOnly) and D3D11 (win32).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.