[ThinEngine] Check if document is available before accessing it #12571
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.
Description
Hi,
In
ThinEngine
thegetHostDocument
method is not react-native "safe", when accessed from a react-native application, we try to accessdocument
without checking that it exists first, thus causing the app to crash.Repro
To repro the issue, all you need is to create a
FollowCamera
and make it follow a target.I got this issue to repro by using this code in an Expo environment:
Cause
What happens here is that at some point, the
Effect
class (packages/dev/core/src/Materials/effect.ts) will try to access the host document by only checking ifIsWindowObjectExist
returns true:This issue is, in this react-native context
window
will exist but notdocument
, leading to this issue.Fix
To fix this, I added a check in
getHostDocument
to make sure thatdocument
actually exist before returning it. If it doesn't, I simply returnnull
.This is my first PR in this repo, please let me know if I forgot anything.