Skip to content

Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX#1703

Merged
bkaradzic-microsoft merged 3 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:weekend/tpc-1652-externaltexture-c4702
May 28, 2026
Merged

Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX#1703
bkaradzic-microsoft merged 3 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:weekend/tpc-1652-externaltexture-c4702

Conversation

@bkaradzic-microsoft
Copy link
Copy Markdown
Contributor

@bkaradzic-microsoft bkaradzic-microsoft commented May 18, 2026

Fixes MSVC C4702 (unreachable code) under /WX in Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp so the OpenGL TU builds cleanly without the project-wide /wd4702 workaround.

What changed

Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp keeps the unimplemented Impl stubs as throw 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 /WX C4702 enforcement.

Plugins/ExternalTexture/CMakeLists.txt - drop the /wd4702 target 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).
  • TU-wide /wd4702 via target_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 /WX enforcement.
  • 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.

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).

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. Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX #1703 - ExternalTexture C4702 build fix
  2. Document accurate root cause for post-#1695 pixel-diff fallouts #1704 - config.json reason rewrites (5 entries)
  3. Document accurate root cause for 17 subtle pixel-diff tests #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:

  1. Bump JsRuntimeHost for File/FileReader polyfill (re-enables 19 GLTF/OBJ tests) #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables)
  2. Add fetch() polyfill over XMLHttpRequest for Playground #1707 - fetch polyfill
  3. Add DOM globals polyfill + native AbortController for Playground #1708 - DOM globals + native AbortController + Android CMake link
  4. Add cubemap auto-expand polyfill for Playground (re-enables 7 PBR tests) #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.

…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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in ExternalTexture_OpenGL.cpp.
  • Remove the OpenGL+MSVC-specific /wd4702 compile option from CMakeLists.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.

Comment thread Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp Outdated
Comment thread Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp
Comment thread Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp Outdated
…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>
Copy link
Copy Markdown
Member

@ryantrem ryantrem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Reviewed by Copilot on behalf of @bghgary]

LGTM barring issues already mentioned, plus one inline comment.

Comment thread Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp Outdated
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>
@bkaradzic-microsoft bkaradzic-microsoft enabled auto-merge (squash) May 28, 2026 00:55
@bkaradzic-microsoft bkaradzic-microsoft merged commit c63332f into BabylonJS:master May 28, 2026
77 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants