Fixed: LDForge would sometimes crash over unitialized data in the GL renderer. This crash sure eluded me for a while. Turned out zoomToFit(), which uses m_width and m_height is called before resizeGL() which initializes these variables. This data is used in an operator new[] call.

Fri, 18 Oct 2013 17:57:42 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 18 Oct 2013 17:57:42 +0300
changeset 510
ee90c55dfeef
parent 509
dcacfd2cd81b
child 511
c3787dbd6315

Fixed: LDForge would sometimes crash over unitialized data in the GL renderer. This crash sure eluded me for a while. Turned out zoomToFit(), which uses m_width and m_height is called before resizeGL() which initializes these variables. This data is used in an operator new[] call.

changelog.txt file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
--- a/changelog.txt	Fri Oct 18 17:47:05 2013 +0300
+++ b/changelog.txt	Fri Oct 18 17:57:42 2013 +0300
@@ -34,6 +34,7 @@
 	and the algorithm can terminate early, hopefully this will save a few cycles on large parts.
 - The camera icons now draw real tooltips instead of emulated ones.
 - Color icon border now reflects the color's edge color.
+- Fixed: LDForge would sometimes crash during startup over uninitialized data in the GL renderer.
 - Fixed: The message log was still written with black text with dark backgrounds.
 
 =================================================
--- a/src/file.cpp	Fri Oct 18 17:47:05 2013 +0300
+++ b/src/file.cpp	Fri Oct 18 17:57:42 2013 +0300
@@ -298,7 +298,7 @@
 		// Trim the trailing newline
 		qchar c;
 
-		while (!line.isEmpty() && (c = line[line.length() - 1]) == '\n' || c == '\r')
+		while (!line.isEmpty() && ((c = line[line.length() - 1]) == '\n' || c == '\r'))
 			line.chop (1);
 
 		LDObject* obj = parseLine (line);
--- a/src/gldraw.cpp	Fri Oct 18 17:47:05 2013 +0300
+++ b/src/gldraw.cpp	Fri Oct 18 17:57:42 2013 +0300
@@ -107,9 +107,9 @@
 	m_editMode = Select;
 	m_rectdraw = false;
 	m_panning = false;
+	m_firstResize = true;
 	setFile (null);
 	setDrawOnly (false);
-	resetAngles();
 	setMessageLog (null);
 
 	m_toolTipTimer = new QTimer (this);
@@ -351,6 +351,14 @@
 {	m_width = w;
 	m_height = h;
 
+	// If this is the first call to resizeGL, reset the angles. We cannot call
+	// resetAngles() in the initializer because it does not know m_width or m_height,
+	// which zoomToFit() must know.
+	if (m_firstResize)
+	{	m_firstResize = false;
+		resetAngles();
+	}
+
 	calcCameraIcons();
 
 	glViewport (0, 0, w, h);
--- a/src/gldraw.h	Fri Oct 18 17:47:05 2013 +0300
+++ b/src/gldraw.h	Fri Oct 18 17:57:42 2013 +0300
@@ -159,14 +159,15 @@
 		int                   m_width,
 		                      m_height,
 							  m_totalmove;
-		QList<vertex>          m_drawedVerts;
+		QList<vertex>         m_drawedVerts;
 		bool                  m_rectdraw;
 		vertex                m_rectverts[4];
 		QColor                m_bgcolor;
 		double                m_depthValues[6];
 		LDGLOverlay           m_overlays[6];
-		QList<vertex>          m_knownVerts;
+		QList<vertex>         m_knownVerts;
 		bool                  m_panning;
+		bool                  m_firstResize;
 
 		void           addDrawnVertex (vertex m_hoverpos);
 		void           calcCameraIcons();                                      // Compute geometry for camera icons

mercurial