57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors

Mon, 25 Mar 2013 01:04:20 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 25 Mar 2013 01:04:20 +0200
changeset 67
d523a370a17a
parent 66
12aca5d5a51e
child 68
c637b172d565

57181.dat (Philo's model of the XL-motor) showcased a new problem.. there was no handling of unknown colors which led into crashes. Added stdout warnings, also added mid and dark stone colors

colors.cpp file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
--- a/colors.cpp	Mon Mar 25 00:44:11 2013 +0200
+++ b/colors.cpp	Mon Mar 25 01:04:20 2013 +0200
@@ -64,6 +64,8 @@
 	{45,	"Trans Pink",	"#FF2080",	0.5},
 	{46,	"Trans Yellow",	"#FFEE00",	0.5},
 	{47,	"Clear",		"#FFFFFF",	0.5},
+	{71,	"Medium Stone",	"#A0A0AA",	1.0},
+	{72,	"Dark Stone",	"#60606A",	1.0},
 	{79,	"Ghost White",	"#FFFFFF",	0.875},
 	{294,	"Trans Phosphorus",	"#E0FFB0",	0.6},
 	{378,	"Sand Green",	"#80A080",	1.0},
--- a/gldraw.cpp	Mon Mar 25 00:44:11 2013 +0200
+++ b/gldraw.cpp	Mon Mar 25 01:04:20 2013 +0200
@@ -84,7 +84,11 @@
 		1.0f);
 }
 
+static vector<short> g_daWarnedColors;
 void renderer::setObjectColor (LDObject* obj, bool bBackSide) {
+	if (obj->dColor == -1)
+		return;
+	
 	if (gl_colorbfc &&
 		obj->getType () != OBJ_Line &&
 		obj->getType () != OBJ_CondLine)
@@ -100,6 +104,22 @@
 		setColor (gl_maincolor, glColor4f);
 	else {
 		color* col = g_LDColors[obj->dColor];
+		
+		if (!col) {
+			// Warn about unknown colors, but only once.
+			for (long i = 0; i < g_daWarnedColors.size(); ++i)
+				if (g_daWarnedColors[i] == obj->dColor)
+					return;
+			
+			printf ("%s: Unknown color %d!\n", __func__, obj->dColor);
+			g_daWarnedColors.push_back (obj->dColor);
+			
+			// Set the main color to make the object at least not appear
+			// pitch-black.
+			setColor (gl_maincolor, glColor4f);
+			return;
+		}
+		
 		QColor qCol (col->zColor.chars());
 		
 		if (qCol.isValid ())
--- a/gui.cpp	Mon Mar 25 00:44:11 2013 +0200
+++ b/gui.cpp	Mon Mar 25 01:04:20 2013 +0200
@@ -665,7 +665,9 @@
 		{
 			// If the object isn't in the main or edge color, draw this
 			// list entry in said color.
-			item->setForeground (0, QColor (g_LDColors[obj->dColor]->zColor.chars()));
+			color* col = g_LDColors[obj->dColor];
+			if (col)
+				item->setForeground (0, QColor (col->zColor.chars()));
 		}
 		
 		obj->qObjListEntry = item;
--- a/ldtypes.cpp	Mon Mar 25 00:44:11 2013 +0200
+++ b/ldtypes.cpp	Mon Mar 25 01:04:20 2013 +0200
@@ -244,10 +244,6 @@
 LDTriangle::~LDTriangle () {}
 LDVertex::~LDVertex () {}
 
-#define TRANSFORM_TYPE(T,N) \
-	case OBJ_##T: \
-			
-
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================

mercurial