# HG changeset patch # User Santeri Piippo # Date 1364166260 -7200 # Node ID d523a370a17ad2edb33fe5285b89187bcea811b5 # Parent 12aca5d5a51ed17405546151828cb99c05868a2d 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 diff -r 12aca5d5a51e -r d523a370a17a colors.cpp --- 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}, diff -r 12aca5d5a51e -r d523a370a17a gldraw.cpp --- 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 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 ()) diff -r 12aca5d5a51e -r d523a370a17a gui.cpp --- 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; diff -r 12aca5d5a51e -r d523a370a17a ldtypes.cpp --- 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: \ - - // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // =============================================================================