Blob Blame History Raw
From 08c5f2133c9dbc8b986bc727c0b9768d9e45ccfd Mon Sep 17 00:00:00 2001
From: Youness Alaoui <kakaroto@kakaroto.homelinux.net>
Date: Tue, 7 Jul 2015 15:48:07 -0400
Subject: [PATCH] Prevent multiple calls to afterSplashCallback

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          | 18 +++++++++---------
 Cura/gui/splashScreen.py |  8 ++++----
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/Cura/gui/app.py b/Cura/gui/app.py
index 8f4fb00..3caf494 100644
--- a/Cura/gui/app.py
+++ b/Cura/gui/app.py
@@ -99,6 +99,12 @@ def Win32SocketListener(self, port):
 		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 @@ def afterSplashCallback(self):
 			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)
diff --git a/Cura/gui/splashScreen.py b/Cura/gui/splashScreen.py
index 44bad77..a3568a0 100644
--- a/Cura/gui/splashScreen.py
+++ b/Cura/gui/splashScreen.py
@@ -14,13 +14,13 @@ def __init__(self, callback):
 		# 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()