Skip to content

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

Open
bkaradzic-microsoft wants to merge 2 commits into
BabylonJS:masterfrom
bkaradzic-microsoft:weekend/tpc-1652-externaltexture-c4702
Open

Fix ExternalTexture_OpenGL throw-stubs to avoid MSVC C4702 under /WX#1703
bkaradzic-microsoft wants to merge 2 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

Replaces throw "not implemented" stubs in Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp with inert default-value returns. The dispatcher in ExternalTexture_Shared.h no longer trips MSVC C4702 (unreachable code) under /WX, so the /wd4702 workaround can be removed from Plugins/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).

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. Add File/Blob/FileReader polyfill for Playground (re-enables 19 GLTF 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 on lines 30 to 40
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"};
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread Plugins/ExternalTexture/Source/ExternalTexture_OpenGL.cpp
Comment on lines +14 to +20
// 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.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

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.

3 participants