Commit 170d6649 authored by David Gobbi's avatar David Gobbi

Fix bad SetColor/GetColor interaction in vtkProperty.

The SetColor() method calls SetAmbientColor(), SetDiffuseColor(),
and SetSpecularColor() and each of these can potentially trigger
a ModifiedEvent.  However, if the ModifiedEvent callback calls
GetColor(), which it often will, this causes Bad Things to happen
because GetColor() calls ComputeCompositeColor() which re-computes
this->Color based on the values of AmbientColor, DiffuseColor, and
SpecularColor.  The fix is to make sure that Modified() is not
called until all of the ivars have been set.

Change-Id: I00a6799a1a9e31a6b28e102e11e4a6bd71f18d71
parent b6105152
......@@ -140,15 +140,35 @@ void vtkProperty::DeepCopy(vtkProperty *p)
//----------------------------------------------------------------------------
void vtkProperty::SetColor(double r, double g, double b)
{
// Really should set the placeholder Color[3] variable
this->Color[0] = r;
this->Color[1] = g;
this->Color[2] = b;
// Use Set macros to insure proper modified time behavior
this->SetAmbientColor(this->Color);
this->SetDiffuseColor(this->Color);
this->SetSpecularColor(this->Color);
double newColor[3] = { r, g, b };
// SetColor is shorthand for "set all colors"
double *color[4] = {
this->Color,
this->AmbientColor,
this->DiffuseColor,
this->SpecularColor
};
// Set colors, and check for changes
bool modified = false;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
if (color[i][j] != newColor[j])
{
modified = true;
color[i][j] = newColor[j];
}
}
}
// Call Modified() if anything changed
if (modified)
{
this->Modified();
}
}
//----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment