Skip to content

Commit 00a84a3

Browse files
authored
MAINT: Fix ref cycle with vtkPolyData (mne-tools#13336)
1 parent 9d114d6 commit 00a84a3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

doc/sphinxext/mne_doc_utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import numpy as np
1414
import pyvista
1515
import sphinx.util.logging
16+
from sphinx.errors import ExtensionError
1617

1718
import mne
1819
from mne.utils import (
19-
_assert_no_instances,
20+
_assert_no_instances as _assert_no_instances_mne,
21+
)
22+
from mne.utils import (
2023
_get_extra_data_path,
2124
sizeof_fmt,
2225
)
@@ -104,6 +107,14 @@ def reset_warnings(gallery_conf, fname):
104107
t0 = time.time()
105108

106109

110+
def _assert_no_instances(cls, when):
111+
"""Wrap our internal one but make the traceback nicer when it fails."""
112+
try:
113+
_assert_no_instances_mne(cls, when)
114+
except Exception as exc:
115+
raise ExtensionError(str(exc)) from None
116+
117+
107118
def reset_modules(gallery_conf, fname, when):
108119
"""Do the reset."""
109120
import matplotlib.pyplot as plt

mne/gui/_coreg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import threading
1212
import time
13+
import weakref
1314
from contextlib import contextmanager
1415
from functools import partial
1516
from pathlib import Path
@@ -914,7 +915,7 @@ def _on_pick(self, vtk_picker, event):
914915
mesh = vtk_picker.GetDataSet()
915916
if mesh is None or cell_id == -1 or not self._mouse_no_mvt:
916917
return
917-
if not any(mesh is target for target in self._picking_targets):
918+
if not any(mesh is target() for target in self._picking_targets):
918919
return
919920
pos = np.array(vtk_picker.GetPickPosition())
920921
vtk_cell = mesh.GetCell(cell_id)
@@ -1342,7 +1343,7 @@ def _add_head_surface(self):
13421343
key = "low"
13431344
self._update_actor("head", head_actor)
13441345
# mark head surface mesh to restrict picking
1345-
self._picking_targets.append(head_surf)
1346+
self._picking_targets.append(weakref.ref(head_surf))
13461347
# We need to use _get_processed_mri_points to incorporate grow_hair
13471348
rr = self.coreg._get_processed_mri_points(key) * self.coreg._scale.T
13481349
head_surf.points = rr

0 commit comments

Comments
 (0)