Skip to content

Type error in emscripten_webgl_do_create_context #22943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JoeOsborn opened this issue Nov 15, 2024 · 8 comments
Closed

Type error in emscripten_webgl_do_create_context #22943

JoeOsborn opened this issue Nov 15, 2024 · 8 comments

Comments

@JoeOsborn
Copy link
Contributor

JoeOsborn commented Nov 15, 2024

If client code asks for explicit swap control, a transferred canvas record is obtained from GL.offscreenCanvases, but then that record (and not the underlying OffscreenCanvas) is passed through to GL.createContext, which expects an actual offscreen canvas. The fix is to add ....offscreenCanvas || ....canvas on the end of line 174, or else to change the code of emscripten_webgl_do_create_context to unpack the canvas.

canvas = GL.offscreenCanvases[canvas.id];

@JoeOsborn
Copy link
Contributor Author

JoeOsborn commented Nov 15, 2024

findCanvasEventTarget has a similar bug, in that it will sometimes return a key from GL.offscreenCanvases, sometimes return an element from GL.offscreenCanvases, and sometimes return an arbitrary HTML element. It should always return something of a reasonable type, whether or not offscreen canvas support is enabled. (In particular it does not make sense for it to sometimes return an element of GL.offscreenCanvases and sometimes an HTML element.)

@sbc100
Copy link
Collaborator

sbc100 commented Nov 15, 2024

Hmm, so in that case it seems like that GL.createContext call will always fail if explicitSwapControl is requested and transferControlToOffscreen exists (i.e. offscreen canvas is supported).

I guess that means we don't have any testing of this configuration?

Would you have time to send a PR for that? It seems like the fix would be to add .canvas to the end of line 174 (e.g. canvas = GL.offscreenCanvases[canvas.id].canvas?

@JoeOsborn
Copy link
Contributor Author

JoeOsborn commented Nov 16, 2024

I tried adding .canvas there, but sometimes the result is later accessed by its canvasSharedPtr or offscreenCanvas fields. I think this function’s callers should be checked to see which ones want shared pointers to offscreen/transferred canvases and should use the GL.offscreenCanvases map only, and which ones want “an element of type canvas or offscreencanvas” and need to return the element’s offscreen canvas or canvas fields if it has been transferred, or the result of findEventTarget otherwise.

I’m planning to look into this Monday in case no one with more expertise has a chance to look by then.

@sbc100
Copy link
Collaborator

sbc100 commented Nov 16, 2024

The function (emscripten_webgl_do_create_context) is returning the result of GL.createContext though right? Not the canvas.

The canvas variable on line 174 is only ever used in the call to GL.createContext isn't it? I don't see it used anywhere else.

@JoeOsborn
Copy link
Contributor Author

Sorry, by “this function” I meant findCanvasEventTarget. I think you’re right that adding .canvas in do_create_context is the right fix, but other similar issues arise from the incompatible types coming out of findCanvasEventTarget.

@sbc100
Copy link
Collaborator

sbc100 commented Nov 16, 2024

OK that sounds right. I guess we can/should fix do_create_context separately, and we should try to add some testing (since I guess there cannot be any testing today since the GL.createContext will fail in this code path won't it?

@JoeOsborn
Copy link
Contributor Author

I believe changing just do_create_context is enough. I can make PRs tomorrow for this and for #22942 as two separate patches.

JoeOsborn added a commit to JoeOsborn/emscripten that referenced this issue Nov 19, 2024
kripken pushed a commit that referenced this issue Nov 22, 2024
…#22958)

Fixes a type error in #22943 when creating a context with explicit swap
control.
@JoeOsborn
Copy link
Contributor Author

This was resolved by #22958 .

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

No branches or pull requests

2 participants