Fix camera.screenToWorld returning NaN when called in initialize#8950
Merged
Conversation
screenToWorld divides by device.clientRect, which initializes to {0,0}
and is only refreshed by device.update() in the frame loop, after start()
fires initialize/postInitialize. The WebGL device constructor called
updateClientRect() so its rect was valid early, but the WebGPU constructor
did not, leaving clientRect at {0,0} and producing NaN results.
Move the updateClientRect() call into the base GraphicsDevice constructor
so all backends have a valid clientRect before the first frame, and remove
the now-redundant WebGL-specific call.
Fixes #8932
Build size reportThis PR changes the size of the minified bundles.
|
willeastcott
added a commit
to playcanvas/developer-site
that referenced
this pull request
Jul 1, 2026
Engine 2.20.0 (playcanvas/engine#8950) moved updateClientRect() into the base GraphicsDevice constructor, which calls canvas.getBoundingClientRect(). @playcanvas/react constructs a NullGraphicsDevice with a bare mock canvas object at module scope for SSR, so importing it during Docusaurus static site generation now throws, failing all 639 doc pages. Pin the engine to 2.19.x (tilde range, since a caret would re-resolve to 2.20.x) until the upstream fixes land. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 1, 2026
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 #8932.
CameraComponent#screenToWorldreturned NaN when called from a script'sinitialize/postInitialize(or the appinitializeevent) on WebGPU, while working correctly on WebGL.Cause:
screenToWorlddivides bydevice.clientRect.width/height.clientRectinitializes to{0, 0}and is only refreshed bydevice.update(), which runs in the frame loop afterapp.start()firesinitialize/postInitialize. The WebGL device constructor happened to callupdateClientRect(), so its rect was valid early; the WebGPU device constructor did not, leavingclientRectat{0, 0}until the first frame — causing a divide-by-zero and NaN results.Changes:
updateClientRect()call into the baseGraphicsDeviceconstructor soclientRectis valid before the first frame on all backends (WebGL, WebGPU, and any future ones).