Skip to content
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
48 changes: 40 additions & 8 deletions src/composables/useWebGLWatchdog.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
import { captureException, captureMessage } from '@sentry/vue';
import { captureMessage } from '@sentry/vue';
import vtkViewProxy from '@kitware/vtk.js/Proxy/Core/ViewProxy';
import vtkProxyManager from '@kitware/vtk.js/Proxy/Core/ProxyManager';
import { useEventListener, useThrottleFn } from '@vueuse/core';
import { Maybe } from '@/src/types';
import { useProxyManager } from '@/src/composables/proxyManager';
import { Messages } from '../constants';
import { useMessageStore } from '../store/messages';
import { onProxyManagerEvent, ProxyManagerEvent } from './onProxyManagerEvent';

/**
* Collects relevant context for debugging 3D crashes.
* @returns
*/
function getVolumeMapperContext(pxm: Maybe<vtkProxyManager>) {
if (!pxm) return null;

const view3d = pxm.getViews().find((view) => view.isA('vtkLPSView3DProxy'));
if (!view3d) return null;

const ren = view3d.getRenderer();
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() {
const watchdogs = new Map<string, () => void>();
const pxm = useProxyManager();

const reportError = useThrottleFn((event) => {
const reportError = useThrottleFn(() => {
const messageStore = useMessageStore();
messageStore.addError(Messages.WebGLLost.title, Messages.WebGLLost.details);
if (event) {
captureException(event);
} else {
captureMessage('WebGL2 context was lost');
}
}, 100);
captureMessage('WebGL2 context was lost', {
contexts: {
vtk: {
volumeMapper: getVolumeMapperContext(pxm),
},
},
});
}, 150);

onProxyManagerEvent(ProxyManagerEvent.ProxyCreated, (id, obj) => {
if (!obj || !obj.isA('vtkViewProxy')) return;
Expand Down