diff --git a/src/core/Environment.tsx b/src/core/Environment.tsx index 0f5e00cab..df9fecd72 100644 --- a/src/core/Environment.tsx +++ b/src/core/Environment.tsx @@ -100,6 +100,7 @@ export function EnvironmentCube({ }: EnvironmentProps) { const texture = useEnvironment(rest) const defaultScene = useThree((state) => state.scene) + React.useLayoutEffect(() => { return setEnvProps(background, scene, defaultScene, texture, { backgroundBlurriness: blur ?? backgroundBlurriness, @@ -109,6 +110,13 @@ export function EnvironmentCube({ environmentRotation, }) }) + + React.useEffect(() => { + return () => { + texture.dispose() + } + }, [texture]) + return null } @@ -142,6 +150,12 @@ export function EnvironmentPortal({ return fbo }, [resolution]) + React.useEffect(() => { + return () => { + fbo.dispose() + } + }, [fbo]) + React.useLayoutEffect(() => { if (frames === 1) { const autoClear = gl.autoClear @@ -202,6 +216,12 @@ function EnvironmentGround(props: EnvironmentProps) { React.useMemo(() => extend({ GroundProjectedEnvImpl }), []) + React.useEffect(() => { + return () => { + textureDefault.dispose() + } + }, [textureDefault]) + const args = React.useMemo<[CubeTexture | Texture]>(() => [texture], [texture]) const height = (props.ground as any)?.height const radius = (props.ground as any)?.radius