]> git.mxchange.org Git - flightgear.git/commitdiff
Fix a segmentation fault when switching to a new style and selecting a new dialog...
authorehofman <ehofman>
Mon, 18 Jul 2005 10:00:02 +0000 (10:00 +0000)
committerehofman <ehofman>
Mon, 18 Jul 2005 10:00:02 +0000 (10:00 +0000)
src/GUI/dialog.cxx
src/GUI/new_gui.cxx
src/GUI/new_gui.hxx

index 5f415f065bfca57deb205bd719f0977687e253cc..722fab29f78a7fee4c8e05e5a84d0c58a1b2cf81 100644 (file)
@@ -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());
     }
 }
 
index a7b1ddb2e9618d5388dace7165e3794f18a7ce8d..a93a0ce1e7b2043a528c3a64e9d34a19d17a93d8 100644 (file)
@@ -379,17 +379,17 @@ FGColor::merge(const SGPropertyNode *node)
 }
 
 bool
-FGColor::merge(const FGColorcolor)
+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;
 }
 
index dbe1904fc876cb5ab0b0f6dafd4a07674072e305..f39ddd232676688224840736c8fe7f9943b8bd8d 100644 (file)
@@ -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 <red> etc.
     bool merge(const SGPropertyNode *prop);
-    bool merge(const FGColorcolor);
+    bool merge(const FGColor *color);
 
     bool set(const SGPropertyNode *prop) { clear(); return merge(prop); };
-    bool set(const FGColorcolor) { 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;