From 276c7efe5851a8f8de04af3fa56bff052025ca20 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 11 Apr 2020 14:03:42 +0200 Subject: [PATCH] Avoid "wrapped C/C++ object has been deleted" when closing wx window. A RuntimeError is otherwise triggered when closing a wx window by clicking the "x" button on the top right. Bisects to bce6263 which fixed another issue with wx... --- lib/matplotlib/backends/backend_wx.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 63c02979a6e8..cf251da531ce 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -1058,7 +1058,9 @@ def show(self): def destroy(self, *args): # docstring inherited _log.debug("%s - destroy()", type(self)) - self.frame.Close() + frame = self.frame + if frame: # Else, may have been already deleted, e.g. when closing. + frame.Close() wxapp = wx.GetApp() if wxapp: wxapp.Yield()