pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.85k stars 641 forks source link

WeakMap key must be an Object #1948

Open fl1k opened 2 months ago

fl1k commented 2 months ago

Problem description:

I am using Expo, I keep getting this error every time I try using functionality of either fiber or drei TypeError: WeakMap key must be an Object, js engine: hermes From drei: import { Environment } from '@react-three/drei/native' From fiber: useLoader(TextureLoader) - I fixed it by switching to three texture loading with new TextureLoader()

Relevant code:

  <View style={{flex: 3}}>
                        <Suspense>
                            <Canvas shadows
                                    onCreated={(state) => {
                                        const _gl = state.gl.getContext();
                                        const pixelStorei = _gl.pixelStorei.bind(_gl);
                                        _gl.pixelStorei = function (...args) {
                                            const [parameter] = args;
                                            switch (parameter) {
                                                case _gl.UNPACK_FLIP_Y_WEBGL:
                                                    return pixelStorei(...args);
                                            }
                                        };
                                    }}
                            >
                                <OrbitControls/>
                                <mesh position={[0, -0.25, 0]}
                                      ref={mesh}
                                      material={materials}

                                >
                                    <boxGeometry args={[w, w * aspect, 0.05]}/>
                                </mesh>
                                <ambientLight intensity={0.8 * Math.PI}/>
                                <Environment preset="lobby" />

                            </Canvas>
                        </Suspense>
                    </View>

Am I doing something wrong? I have been debugging this for 6-7 hours and couldn't find a solution, I found that this happens when there is three version mismatch but I don't have multiple three versions installed, is there a specific version needed for react-fiber? Error is thrown at three.cjs (22974:21)

Suggested solution:

fl1k commented 2 months ago

Adding Environment to the Canvas causes the error