Skip to content

Conversation

@andvgal
Copy link
Contributor

@andvgal andvgal commented Oct 22, 2025

This is a blind fix for #25618

var t = c.GLctx;
if (!t) return {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_TARGET }}};
t = t.getContextAttributes();
if (!t) return {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_TARGET }}};
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about

var t = c.GLctx?.getContextAttributes();
if (!t) return {{{ cDefs.EMSCRIPTEN_RESULT_INVALID_TARGET }}};

?

Although do note that if the GL context is lost, then all subsequent GL calls will fail as well. So if you have a code path that can somehow recover (if it is an iOS 26.1 internal bug, one might not exist), you will need to call emscripten_is_webgl_context_lost() or register to emscripten_set_webglcontextlost_callback() to be notified of a context loss, to do something else.

I.e. the issue will likely not be isolated to this function, but all subsequent GL operations will fail as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First of all, that is a blind fix for a runtime exception. The fact that the context is not usable any more is out of scope.

The refactoring suggestion imposes another minimal ECMAScript version. I am not that familiar with the project and its application, but the code around suggests ES6-level of coding about when WebAssembly got first introduced. Optional chaining is ES2020.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Emscripten project uses Babel to transpile to older ES standards. Using ?. is ok here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, then following your advice.

@andvgal andvgal force-pushed the dev/25618-js-exception-on-WebGL-getContextAttributes branch from b4e9dea to 6038992 Compare October 22, 2025 14:28
@juj juj enabled auto-merge (squash) October 22, 2025 14:32
@juj juj disabled auto-merge October 22, 2025 19:42
@juj juj merged commit 9b1c279 into emscripten-core:main Oct 22, 2025
30 of 32 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.

2 participants