chiark / gitweb /
Prevent multiple calls to afterSplashCallback
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Tue, 7 Jul 2015 19:48:07 +0000 (15:48 -0400)
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Tue, 7 Jul 2015 20:05:15 +0000 (16:05 -0400)
This fixes issue #133. Problem was that if splash.OnClose was called
before the afterSplashCallback was done (such as, if it's blocking
on a configWizard), then the callback would be called again.
This also fixes a segmentation fault if you cancel the initial config wizard
by making sure the callback is done outside the event thread and splash
destruction is done at the proper time and from the proper thread.

Cura/gui/app.py
Cura/gui/splashScreen.py

index 8f4fb0034650c9ddd753b6ed93820f9a9d0a186f..3caf494f4bd5b63ba6fd9f4d8b4957fa0fee75d1 100644 (file)
@@ -99,6 +99,12 @@ class CuraApp(wx.App):
                except:
                        pass
 
+       def destroySplashScreen(self):
+               if self.splash is not None:
+                       self.splash.Show(False)
+                       self.splash.Destroy()
+                       self.splash = None
+
        def afterSplashCallback(self):
                #These imports take most of the time and thus should be done after showing the splashscreen
                import webbrowser
@@ -134,26 +140,20 @@ class CuraApp(wx.App):
                        exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'Rocktopus.stl'))
 
                        self.loadFiles = [exampleFile]
-                       if self.splash is not None:
-                               self.splash.Show(False)
-                               self.splash = None
+                       self.destroySplashScreen()
                        configWizard.ConfigWizard()
 
                if profile.getPreference('check_for_updates') == 'True':
                        newVersion = version.checkForNewerVersion()
                        if newVersion is not None:
-                               if self.splash is not None:
-                                       self.splash.Show(False)
-                                       self.splash = None
+                               self.destroySplashScreen()
                                if wx.MessageBox(_("A new version of Cura is available, would you like to download?"), _("New version available"), wx.YES_NO | wx.ICON_INFORMATION) == wx.YES:
                                        webbrowser.open(newVersion)
                                        return
                if profile.getMachineSetting('machine_name') == '':
                        return
                self.mainWindow = mainWindow.mainWindow()
-               if self.splash is not None:
-                       self.splash.Show(False)
-                       self.splash = None
+               self.destroySplashScreen()
                self.SetTopWindow(self.mainWindow)
                self.mainWindow.Show()
                self.mainWindow.OnDropFiles(self.loadFiles)
index 44bad77acd2db0cf8c08439ce201776b294b020e..a3568a0da57ead5a09201745511d4a79dfce5099 100644 (file)
@@ -14,13 +14,13 @@ class splashScreen(wx.SplashScreen):
                # rectangle while the app is loading
                self.Bind(wx.EVT_CLOSE, self.OnClose)
 
-       def DoDestroy(self):
-               self.Destroy()
 
        def OnClose(self, e):
                if self.callback:
                        # Avoid calling the callback twice
-                       self.callback()
+                       cb = self.callback
                        self.callback = None
-               wx.CallAfter(self.DoDestroy)
+                       # The callback will destroy us
+                       wx.CallAfter(cb)
+
                e.Skip()