IDE: fix segfault when unselecting network discovery in URI editor wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 16 Jan 2023 16:22:44 +0100
branchwxPython4
changeset 3717 da9ffd572551
parent 3716 3dafdb6ad023
child 3718 7841b651d601
IDE: fix segfault when unselecting network discovery in URI editor
controls/DiscoveryPanel.py
--- a/controls/DiscoveryPanel.py	Sun Jan 15 21:40:58 2023 +0100
+++ b/controls/DiscoveryPanel.py	Mon Jan 16 16:22:44 2023 +0100
@@ -129,10 +129,23 @@
         self.IfacesMonitorTimer.Start(2000)
         self.Bind(wx.EVT_TIMER, self.IfacesMonitor, self.IfacesMonitorTimer)
 
+    def _cleanup(self):
+        if self.IfacesMonitorTimer is not None:
+            self.IfacesMonitorTimer.Stop()
+            self.IfacesMonitorTimer = None
+        if self.Browser is not None:
+            self.Browser.cancel()
+            self.Browser = None
+        if self.ZeroConfInstance is not None:
+            self.ZeroConfInstance.close()
+            self.ZeroConfInstance = None
+
     def __del__(self):
-        self.IfacesMonitorTimer.Stop()
-        self.Browser.cancel()
-        self.ZeroConfInstance.close()
+        self._cleanup()
+
+    def Destroy(self):
+        self._cleanup()
+        wx.Panel.Destroy(self)
 
     def IfacesMonitor(self, event):
         NewState = get_all_addresses(socket.AF_INET)