diff --git a/src/composables/useWebGLWatchdog.ts b/src/composables/useWebGLWatchdog.ts index 26016f938..e7c07eed8 100644 --- a/src/composables/useWebGLWatchdog.ts +++ b/src/composables/useWebGLWatchdog.ts @@ -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) { + 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 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;