Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a guard against WebGL errors #6371

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/docusaurus/src/components/StarrySky.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect, useRef} from 'react';
import * as THREE from 'three';
import React, {useEffect, useRef, useState} from 'react';
import * as THREE from 'three';

import styles from './StarrySky.module.css';
import styles from './StarrySky.module.css';

const r = 1000;
const FACTOR = 4;
Expand Down Expand Up @@ -143,11 +143,19 @@ function installSky(canvas: HTMLCanvasElement) {

export function StarrySky() {
const canvasRef = useRef<HTMLCanvasElement>(null);
const [isCrashed, setIsCrashed] = useState(false);

useEffect(() => {
return installSky(canvasRef.current!);
try {
installSky(canvasRef.current!);
} catch {
setIsCrashed(true);
}
}, []);

if (isCrashed)
return null;

return (
<canvas className={styles.canvas} ref={canvasRef}/>
);
Expand Down
Loading