Skip to content

Commit 8dc15e0

Browse files
authored
Merge pull request #514 from Kitware/improved-error-reporting
Improved error reporting
2 parents 0b21084 + acb79cd commit 8dc15e0

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

src/composables/useWebGLWatchdog.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { captureException, captureMessage } from '@sentry/vue';
12
import vtkViewProxy from '@kitware/vtk.js/Proxy/Core/ViewProxy';
23
import { useEventListener, useThrottleFn } from '@vueuse/core';
34
import { Messages } from '../constants';
@@ -7,9 +8,14 @@ import { onProxyManagerEvent, ProxyManagerEvent } from './onProxyManagerEvent';
78
export function useWebGLWatchdog() {
89
const watchdogs = new Map<string, () => void>();
910

10-
const reportError = useThrottleFn(() => {
11+
const reportError = useThrottleFn((event) => {
1112
const messageStore = useMessageStore();
1213
messageStore.addError(Messages.WebGLLost.title, Messages.WebGLLost.details);
14+
if (event) {
15+
captureException(event);
16+
} else {
17+
captureMessage('WebGL2 context was lost');
18+
}
1319
}, 100);
1420

1521
onProxyManagerEvent(ProxyManagerEvent.ProxyCreated, (id, obj) => {

src/utils/errorReporting.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getGPUInfo } from '@/src/utils/gpuInfo';
12
import * as Sentry from '@sentry/vue';
23
import { useLocalStorage } from '@vueuse/core';
34
import { defineStore } from 'pinia';
@@ -16,6 +17,8 @@ export const init = (app: App<Element>) => {
1617
app,
1718
dsn: VITE_SENTRY_DSN,
1819
});
20+
21+
Sentry.setContext('gpu', getGPUInfo());
1922
};
2023

2124
const setEnabled = (enabled: boolean) => {

src/utils/gpuInfo.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Maybe } from '@/src/types';
2+
3+
/**
4+
* Retrieves the GPU renderer and vendor info.
5+
* @returns
6+
*/
7+
export function getGPUInfo() {
8+
let canvas: Maybe<OffscreenCanvas | HTMLCanvasElement> = null;
9+
if (typeof OffscreenCanvas !== 'undefined') {
10+
canvas = new OffscreenCanvas(1, 1);
11+
} else if (typeof document !== 'undefined') {
12+
canvas = document.createElement('canvas');
13+
} else {
14+
throw new Error('Cannot init a canvas');
15+
}
16+
17+
const gl = canvas.getContext('webgl2') as WebGL2RenderingContext;
18+
if (!gl) {
19+
throw new Error('Cannot get a WebGL2 context');
20+
}
21+
22+
const info = {
23+
renderer: '',
24+
vendor: '',
25+
};
26+
27+
const dbg = gl.getExtension('WEBGL_debug_renderer_info');
28+
if (dbg) {
29+
info.renderer = gl.getParameter(dbg.UNMASKED_RENDERER_WEBGL);
30+
info.vendor = gl.getParameter(dbg.UNMASKED_VENDOR_WEBGL);
31+
} else {
32+
info.renderer = gl.getParameter(gl.RENDERER);
33+
info.vendor = gl.getParameter(gl.VENDOR);
34+
}
35+
36+
return info;
37+
}

0 commit comments

Comments
 (0)