Skip to content

Commit 16f9572

Browse files
authored
Merge pull request #2857 from appwrite/fix-threlte-viewport-crash
fix: Prevent getWorldPosition error in promo shader
2 parents e007707 + 20ac8b3 commit 16f9572

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/lib/components/promos/shader.svelte

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
import { Uniform, MeshBasicMaterial, Vector2 } from 'three';
44
import noise from './threlte/shaders/noise.glsl?raw';
55
import { onMount } from 'svelte';
6-
import { useViewport } from '@threlte/extras';
7-
8-
const { invalidate } = useThrelte();
9-
const viewport = useViewport();
6+
const { invalidate, size } = useThrelte();
107
118
let uAspect: Uniform;
129
let uOpacity: Uniform;
1310
let uTime: Uniform;
1411
let uViewportSize: Uniform;
1512
1613
$effect(() => {
17-
const width = $viewport.width;
18-
const height = $viewport.height;
14+
const width = $size.width || 1;
15+
const height = $size.height || 1;
1916
if (uAspect) {
2017
uAspect.value = width / height;
2118
invalidate();
@@ -30,10 +27,13 @@
3027
let material = $state<MeshBasicMaterial>(new MeshBasicMaterial());
3128
3229
onMount(() => {
33-
uAspect = new Uniform($viewport.width / $viewport.height);
30+
const width = $size.width || 1;
31+
const height = $size.height || 1;
32+
33+
uAspect = new Uniform(width / height);
3434
uOpacity = new Uniform(0);
3535
uTime = new Uniform(0);
36-
uViewportSize = new Uniform(new Vector2($viewport.width, $viewport.height));
36+
uViewportSize = new Uniform(new Vector2(width, height));
3737
3838
material.onBeforeCompile = (shader) => {
3939
shader.uniforms.uTime = uTime;
@@ -104,6 +104,6 @@
104104
</script>
105105

106106
<T.OrthographicCamera position={[0, 0, 10]} fov={10} near={0.1} far={1000} makeDefault />
107-
<T.Mesh scale={[$viewport.width, $viewport.height, 1]} {material}>
107+
<T.Mesh scale={[$size.width || 1, $size.height || 1, 1]} {material}>
108108
<T.PlaneGeometry args={[1, 1]} />
109109
</T.Mesh>

0 commit comments

Comments
 (0)