Skip to content

Commit 9084474

Browse files
committed
Error atom
1 parent 928dae9 commit 9084474

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/views/application-container.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {h} from 'preact'
22
import {getCanvasContext} from '../app-state/getters'
3-
import {memo, useMemo} from 'preact/compat'
3+
import {memo, useEffect, useMemo} from 'preact/compat'
44
import {useActiveProfileState} from '../app-state/active-profile-state'
55
import {useTheme} from './themes/theme'
66
import {
@@ -20,10 +20,21 @@ import {Application} from './application'
2020
export const ApplicationContainer = memo(() => {
2121
const canvas = useAtom(glCanvasAtom)
2222
const theme = useTheme()
23-
const canvasContext = useMemo(
24-
() => (canvas ? getCanvasContext({theme, canvas}) : null),
25-
[theme, canvas],
26-
)
23+
const {canvasContext, error: canvasError} = useMemo(() => {
24+
if (!canvas) return {canvasContext: null, error: null}
25+
try {
26+
return {canvasContext: getCanvasContext({theme, canvas}), error: null}
27+
} catch (e) {
28+
console.error('Failed to create WebGL context:', e)
29+
return {canvasContext: null, error: e}
30+
}
31+
}, [theme, canvas])
32+
33+
useEffect(() => {
34+
if (canvasError) {
35+
errorAtom.set(true)
36+
}
37+
}, [canvasError])
2738

2839
return (
2940
<ProfileSearchContextProvider>

0 commit comments

Comments
 (0)