Skip to content

Commit

Permalink
Merge pull request #517 from Kitware/report-generic-contextlost-error
Browse files Browse the repository at this point in the history
fix(useWebGLWatchdog): just report message
  • Loading branch information
floryst authored Nov 24, 2023
2 parents d7d9775 + 426b69f commit 4e27240
Showing 1 changed file with 40 additions and 8 deletions.
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

0 comments on commit 4e27240

Please sign in to comment.