From a2eb1fc74eba3031b4429516240a8cadc669cc5d Mon Sep 17 00:00:00 2001 From: Mark Eibes Date: Wed, 4 Dec 2024 19:49:23 +0100 Subject: [PATCH] Make looking for parent not crash I have trouble with this [codesandbox](https://codesandbox.io/p/sandbox/scene-transitions-reveal-forked-nnj7py?file=%2Fpackage.json%3A19%2C8): It uses the latest versions of react and fiber. Every frame it fails to find a parent and logs an error. I suppose this is because [this logic](https://github.com/pmndrs/drei/blob/master/src/core/RenderTexture.tsx#L60-L66) doesn't work anymore. I'm proposing a safer variant here, but I'm not sure if internals have changed and there's a better way. --- src/core/RenderTexture.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/RenderTexture.tsx b/src/core/RenderTexture.tsx index 077b1ee4c..1b7974ce2 100644 --- a/src/core/RenderTexture.tsx +++ b/src/core/RenderTexture.tsx @@ -61,7 +61,7 @@ export const RenderTexture: ForwardRefComponent = /* @__PU // need to transform event coordinates to local coordinates. We use r3f internals to find the // next Object3D. let parent = (fbo.texture as any)?.__r3f.parent - while (parent && !(parent instanceof THREE.Object3D)) { + while (parent && !(parent instanceof THREE.Object3D) && parent.__r3f) { parent = parent.__r3f.parent } if (!parent) return false