-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathuseWebGLWatchdog.ts
More file actions
52 lines (44 loc) · 1.54 KB
/
useWebGLWatchdog.ts
File metadata and controls
52 lines (44 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { captureMessage } from '@sentry/vue';
import { useEventListener, useThrottleFn } from '@vueuse/core';
import { Messages } from '@/src/constants';
import { useMessageStore } from '@/src/store/messages';
import { View } from '@/src/core/vtk/types';
import { vtkFieldRef } from '@/src/core/vtk/vtkFieldRef';
import { MaybeRef, computed, unref } from 'vue';
import { Maybe } from '@/src/types';
const THROTTLE_THRESHOLD = 250; // ms
/**
* Collects relevant context for debugging 3D crashes.
* @returns
*/
function getVolumeMapperContext(view: View) {
const ren = view.renderer;
const vol = ren.getVolumes()[0];
if (!vol) return null;
const mapper = vol.getMapper();
if (!mapper) return null;
return mapper.get(
'computeNormalFromOpacity',
'autoAdjustSampleDistances',
'maximumSamplesPerRay',
'sampleDistance',
'volumetricScatteringBlending'
);
}
export function useWebGLWatchdog(view: MaybeRef<Maybe<View>>) {
const reportError = useThrottleFn(() => {
const messageStore = useMessageStore();
messageStore.addError(Messages.WebGLLost.title, {
details: Messages.WebGLLost.details,
});
const contexts: Record<string, any> = {};
const viewVal = unref(view);
if (viewVal) {
contexts.vtk = getVolumeMapperContext(viewVal);
}
captureMessage('WebGL2 context was lost', { contexts });
}, THROTTLE_THRESHOLD);
const renWinView = computed(() => unref(view)?.renderWindowView);
const canvas = vtkFieldRef(renWinView, 'canvas');
useEventListener(canvas, 'webglcontextlost', reportError);
}