- fixed crash-on-exit (simply by not running full destruction processing during program termination)

Tue, 29 Jul 2014 13:12:22 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 29 Jul 2014 13:12:22 +0300
changeset 857
e62983881460
parent 856
6bdc03091441
child 858
b6b1afacb7c1

- fixed crash-on-exit (simply by not running full destruction processing during program termination)

src/actions.cc file | annotate | diff | comparison | revisions
src/dialogs.cc file | annotate | diff | comparison | revisions
src/glCompiler.cc file | annotate | diff | comparison | revisions
src/glCompiler.h file | annotate | diff | comparison | revisions
src/glRenderer.cc file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/ldDocument.cc file | annotate | diff | comparison | revisions
src/ldObject.cc file | annotate | diff | comparison | revisions
src/main.cc file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/mainWindow.h file | annotate | diff | comparison | revisions
--- a/src/actions.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/actions.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -172,7 +172,7 @@
 //
 void MainWindow::slot_actionExit()
 {
-	exit (0);
+	Exit();
 }
 
 // =============================================================================
--- a/src/dialogs.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/dialogs.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -233,7 +233,7 @@
 // =============================================================================
 void LDrawPathDialog::slot_exit()
 {
-	exit (0);
+	Exit();
 }
 
 // =============================================================================
--- a/src/glCompiler.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/glCompiler.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -101,6 +101,9 @@
 {
 	glDeleteBuffers (g_numVBOs, &m_vbo[0]);
 	checkGLError();
+
+	if (m_renderer != null)
+		m_renderer->setCompiler (null);
 }
 
 // =============================================================================
@@ -399,3 +402,8 @@
 		}
 	}
 }
+
+void GLCompiler::setRenderer (GLRenderer* renderer)
+{
+	m_renderer = renderer;
+}
--- a/src/glCompiler.h	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/glCompiler.h	Tue Jul 29 13:12:22 2014 +0300
@@ -43,6 +43,7 @@
 	QColor				indexColorForID (int id) const;
 	void				needMerge();
 	void				prepareVBO (int vbonum);
+	void				setRenderer (GLRenderer* compiler);
 	void				stageForCompilation (LDObjectPtr obj);
 	void				unstage (LDObjectPtr obj);
 
@@ -66,14 +67,14 @@
 private:
 	void			compileStaged();
 	void			compileObject (LDObjectPtr obj);
-	void			compilePolygon (LDPolygon& poly, LDObjectPtr topobj, GLCompiler::ObjectVBOInfo* objinfo);
+	void			compilePolygon (LDPolygon& poly, LDObjectPtr topobj, ObjectVBOInfo* objinfo);
 
 	QMap<LDObjectWeakPtr, ObjectVBOInfo>	m_objectInfo;
 	LDObjectWeakList						m_staged; // Objects that need to be compiled
 	GLuint									m_vbo[g_numVBOs];
 	bool									m_vboChanged[g_numVBOs];
 	int										m_vboSizes[g_numVBOs];
-	GLRenderer* const						m_renderer;
+	GLRenderer*								m_renderer;
 };
 
 #define checkGLError() { checkGLError_private (__FILE__, __LINE__); }
--- a/src/glRenderer.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/glRenderer.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -143,6 +143,10 @@
 	for (CameraIcon& info : m_cameraIcons)
 		delete info.img;
 
+	if (messageLog())
+		messageLog()->setRenderer (null);
+
+	m_compiler->setRenderer (null);
 	delete m_compiler;
 	delete m_editmode;
 }
@@ -1130,7 +1134,8 @@
 //
 void GLRenderer::forgetObject (LDObjectPtr obj)
 {
-	compiler()->dropObject (obj);
+	if (compiler() != null)
+		compiler()->dropObject (obj);
 }
 
 // =============================================================================
--- a/src/glRenderer.h	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/glRenderer.h	Tue Jul 29 13:12:22 2014 +0300
@@ -143,7 +143,7 @@
 	PROPERTY (public,	MessageManager*,	messageLog, 	setMessageLog,		STOCK_WRITE)
 	PROPERTY (private,	bool,				isPicking,		setPicking,			CUSTOM_WRITE)
 	PROPERTY (public,	LDDocumentPtr,		document,		setDocument,		CUSTOM_WRITE)
-	PROPERTY (private,	GLCompiler*,		compiler,		setCompiler,		STOCK_WRITE)
+	PROPERTY (public,	GLCompiler*,		compiler,		setCompiler,		STOCK_WRITE)
 	PROPERTY (public,	LDObjectWeakPtr,	objectAtCursor,	setObjectAtCursor,	STOCK_WRITE)
 	PROPERTY (private,	bool,				isCameraMoving,	setCameraMoving,	STOCK_WRITE)
 
--- a/src/ldDocument.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/ldDocument.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -67,7 +67,7 @@
 			LDrawPathDialog dlg (false);
 
 			if (not dlg.exec())
-				exit (0);
+				Exit();
 
 			cfg::LDrawPath = dlg.filename();
 		}
@@ -153,7 +153,10 @@
 //
 LDDocument::~LDDocument()
 {
-	print ("Deleted %1", getDisplayName());
+	// Don't bother during program termination
+	if (IsExiting())
+		return;
+
 	g_allDocuments.removeOne (self());
 	m_flags |= DOCF_IsBeingDestroyed;
 	delete m_history;
--- a/src/ldObject.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/ldObject.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -89,7 +89,7 @@
 	critical ("Created too many objects. Execution cannot continue. You have a "
 		"chance to save any changes to documents, then restart.");
 	(void) safeToCloseAll();
-	exit (0);
+	Exit();
 }
 
 // =============================================================================
@@ -303,6 +303,10 @@
 //
 void LDObject::destroy()
 {
+	// Don't bother during program termination
+	if (IsExiting() or isDestructed())
+		return;
+
 	// If this object was selected, unselect it now
 	if (isSelected())
 		deselect();
@@ -312,7 +316,8 @@
 		document().toStrongRef()->forgetObject (self());
 
 	// Delete the GL lists
-	g_win->R()->forgetObject (self());
+	if (g_win != null)
+		g_win->R()->forgetObject (self());
 
 	// Remove this object from the list of LDObjects
 	g_allObjects.erase (g_allObjects.find (id()));
--- a/src/main.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/main.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -36,6 +36,7 @@
 
 MainWindow* g_win = null;
 static QString g_versionString, g_fullVersionString;
+static bool g_IsExiting (false);
 
 const Vertex g_origin (0.0f, 0.0f, 0.0f);
 const Matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
@@ -79,5 +80,18 @@
 		Config::Save();
 	}
 
-	return app.exec();
+	int result = app.exec();
+	g_IsExiting = true;
+	return result;
 }
+
+bool IsExiting()
+{
+	return g_IsExiting;
+}
+
+void Exit()
+{
+	g_IsExiting = true;
+	exit (EXIT_SUCCESS);
+}
--- a/src/main.h	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/main.h	Tue Jul 29 13:12:22 2014 +0300
@@ -36,3 +36,5 @@
 static const std::nullptr_t null = nullptr;
 
 void assertionFailure (const char* file, int line, const char* funcname, const char* expr);
+bool IsExiting();
+void Exit();
--- a/src/mainWindow.cc	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/mainWindow.cc	Tue Jul 29 13:12:22 2014 +0300
@@ -123,6 +123,11 @@
 	connect (qApp, SIGNAL (aboutToQuit()), this, SLOT (slot_lastSecondCleanup()));
 }
 
+MainWindow::~MainWindow()
+{
+	g_win = null;
+}
+
 // =============================================================================
 //
 void MainWindow::slot_action()
--- a/src/mainWindow.h	Mon Jul 28 16:38:34 2014 +0300
+++ b/src/mainWindow.h	Tue Jul 29 13:12:22 2014 +0300
@@ -76,6 +76,7 @@
 
 public:
 	explicit MainWindow (QWidget* parent = null, Qt::WindowFlags flags = 0);
+	~MainWindow();
 
 	// Rebuilds the object list.
 	void buildObjList();

mercurial