Skip to content

Commit

Permalink
Add _initialized flag for (Base)Plotter against errors in __del__
Browse files Browse the repository at this point in the history
  • Loading branch information
adeak committed Jul 20, 2022
1 parent f506690 commit dd476af
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pyvista/plotting/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def __init__(
"""Initialize base plotter."""
super().__init__(**kwargs) # cooperative multiple inheritance
log.debug('BasePlotter init start')
self._initialized = False

self._theme = pyvista.themes.DefaultTheme()
if theme is None:
# copy global theme to ensure local plot theme is fixed
Expand Down Expand Up @@ -281,6 +283,8 @@ def __init__(
if self.theme.antialiasing:
self.enable_anti_aliasing()

self._initialized = True

@property
def theme(self):
"""Return or set the theme used for this plotter.
Expand Down Expand Up @@ -4720,13 +4724,12 @@ def _datasets(self):

def __del__(self):
"""Delete the plotter."""
# We have to check here if it has the closed attribute as it
# may not exist should the plotter have failed to initialize.
if hasattr(self, '_closed'):
# We have to check here if the plotter was only partially initialized
if self._initialized:
if not self._closed:
self.close()
self.deep_clean()
if hasattr(self, 'renderers'):
if self._initialized:
del self.renderers

def add_background_image(self, image_path, scale=1, auto_resize=True, as_global=True):
Expand Down Expand Up @@ -5163,6 +5166,8 @@ def __init__(
lighting=lighting,
theme=theme,
)
# reset partial initialization flag
self._initialized = False

log.debug('Plotter init start')

Expand Down Expand Up @@ -5256,6 +5261,9 @@ def on_timer(iren, event_id):
if self.enable_depth_peeling():
for renderer in self.renderers:
renderer.enable_depth_peeling()

# some cleanup only necessary for fully initialized plotters
self._initialized = True
log.debug('Plotter init stop')

def show(
Expand Down

0 comments on commit dd476af

Please sign in to comment.