Skip to content

Fix for issue 17769: wx interactive figure close cause crash #19596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 3, 2021
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
24 changes: 12 additions & 12 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,9 +971,13 @@ def _onClose(self, event):
_log.debug("%s - onClose()", type(self))
self.canvas.close_event()
self.canvas.stop_event_loop()
Gcf.destroy(self)
if self:
self.Destroy()
# set FigureManagerWx.frame to None to prevent repeated attempts to
# close this frame from FigureManagerWx.destroy()
self.figmgr.frame = None
# remove figure manager from Gcf.figs
Gcf.destroy(self.figmgr)
# Carry on with close event propagation, frame & children destruction
event.Skip()

def GetToolBar(self):
"""Override wxFrame::GetToolBar as we don't have managed toolbar"""
Expand All @@ -990,11 +994,8 @@ def Destroy(self, *args, **kwargs):
# MPLBACKEND=wxagg python -c 'from pylab import *; plot()'.
if self and not self.IsBeingDeleted():
super().Destroy(*args, **kwargs)
if self.toolbar is not None:
self.toolbar.Destroy()
wxapp = wx.GetApp()
if wxapp:
wxapp.Yield()
# self.toolbar.Destroy() should not be necessary if the close event
# is allowed to propagate.
return True


Expand Down Expand Up @@ -1043,10 +1044,9 @@ def destroy(self, *args):
_log.debug("%s - destroy()", type(self))
frame = self.frame
if frame: # Else, may have been already deleted, e.g. when closing.
frame.Close()
wxapp = wx.GetApp()
if wxapp:
wxapp.Yield()
# As this can be called from non-GUI thread from plt.close use
# wx.CallAfter to ensure thread safety.
wx.CallAfter(frame.Close)

def full_screen_toggle(self):
# docstring inherited
Expand Down