From 06665909090d40adc9fcea3f65f81fcfaf2480fb Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 18 Jul 2005 10:00:02 +0000 Subject: [PATCH] Fix a segmentation fault when switching to a new style and selecting a new dialog. I still need to find out why getColor doesn't work properly. --- src/GUI/dialog.cxx | 26 +++++++++++++------------- src/GUI/new_gui.cxx | 18 +++++++++--------- src/GUI/new_gui.hxx | 12 +++++++----- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 5f415f065..722fab29f 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -670,11 +670,11 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which) if (type == "") type = "dialog"; - FGColor c(_gui->getColor("background")); - c.merge(_gui->getColor(type)); - c.merge(props->getNode("color")); - if (c.isValid()) - object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha()); + FGColor *c = new FGColor(_gui->getColor("background")); + c->merge(_gui->getColor(type)); + c->merge(props->getNode("color")); + if (c->isValid()) + object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha()); const int numcol = 6; const struct { @@ -693,18 +693,18 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which) for (int i = 0; i < numcol; i++) { bool dirty = false; - c.clear(); - c.setAlpha(1.0); + c->clear(); + c->setAlpha(1.0); - dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name)); + dirty |= c->merge(_gui->getColor(type + '-' + pucol[i].name)); if (which & pucol[i].mask) - dirty |= c.merge(props->getNode("color")); + dirty |= c->merge(props->getNode("color")); - if ((pucol[i].mask == LABEL) && !c.isValid()) - dirty |= c.merge(_gui->getColor("label")); + if ((pucol[i].mask == LABEL) && !c->isValid()) + dirty |= c->merge(_gui->getColor("label")); - if (c.isValid() && dirty) - object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha()); + if (c->isValid() && dirty) + object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha()); } } diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index a7b1ddb2e..a93a0ce1e 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -379,17 +379,17 @@ FGColor::merge(const SGPropertyNode *node) } bool -FGColor::merge(const FGColor& color) +FGColor::merge(const FGColor *color) { bool dirty = false; - if (color._red >= 0.0) - _red = color._red, dirty = true; - if (color._green >= 0.0) - _green = color._green, dirty = true; - if (color._blue >= 0.0) - _blue = color._blue, dirty = true; - if (color._alpha >= 0.0) - _alpha = color._alpha, dirty = true; + if (color && color->_red >= 0.0) + _red = color->_red, dirty = true; + if (color && color->_green >= 0.0) + _green = color->_green, dirty = true; + if (color && color->_blue >= 0.0) + _blue = color->_blue, dirty = true; + if (color && color->_alpha >= 0.0) + _alpha = color->_alpha, dirty = true; return dirty; } diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index dbe1904fc..f39ddd232 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -156,11 +156,11 @@ public: virtual FGColor *getColor (const char * name) const { _itt_t it = _colors.find(name); - return it->second; + return (it != _colors.end()) ? it->second : NULL; } virtual FGColor *getColor (const string &name) const { _itt_t it = _colors.find(name.c_str()); - return it->second; + return (it != _colors.end()) ? it->second : NULL; } virtual puFont *getDefaultFont() { return &_font; } @@ -217,15 +217,17 @@ public: FGColor() { clear(); } FGColor(float r, float g, float b, float a = 1.0f) { set(r, g, b, a); } FGColor(const SGPropertyNode *prop) { set(prop); } - FGColor(FGColor *c) { set(c->_red, c->_green, c->_blue, c->_alpha); } + FGColor(FGColor *c) { + if (c) set(c->_red, c->_green, c->_blue, c->_alpha); + } inline void clear() { _red = _green = _blue = _alpha = -1.0f; } // merges in non-negative components from property with children etc. bool merge(const SGPropertyNode *prop); - bool merge(const FGColor& color); + bool merge(const FGColor *color); bool set(const SGPropertyNode *prop) { clear(); return merge(prop); }; - bool set(const FGColor& color) { clear(); return merge(color); } + bool set(const FGColor *color) { clear(); return merge(color); } bool set(float r, float g, float b, float a = 1.0f) { _red = r, _green = g, _blue = b, _alpha = a; return true; -- 2.39.5