]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/tgdb/apt_signs.cxx
Merge branches 'ehofman/config' and 'ehofman/dlerror'
[simgear.git] / simgear / scene / tgdb / apt_signs.cxx
index 34d61c1213522547d28de0a8917fa6828b5892a1..a47dae0c4ba38eaf9b8cdb4df5002efed4d0c5fb 100644 (file)
@@ -106,9 +106,9 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
     osg::Group* object = new osg::Group;
     object->setName(content);
 
-    SGMaterial *material;
-    Effect *lighted_state;
-    Effect *unlighted_state;
+    SGMaterial *material = 0;
+    Effect *lighted_state = 0;
+    Effect *unlighted_state = 0;
 
     // Part I: parse & measure
     for (const char *s = content.data(); *s; s++) {
@@ -220,26 +220,31 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content)
         }
 
         if (newmat.size()) {
-            material = matlib->find(newmat);
-            if (!material) {
+            SGMaterial *m = matlib->find(newmat);
+            if (!m) {
+                // log error, but keep using previous material to at least show something
                 SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
-                continue;
-            }
-
-            // set material states (lighted & unlighted)
-            lighted_state = material->get_effect();
-            string u = newmat + ".unlighted";
-
-            SGMaterial *m = matlib->find(u);
-            if (m) {
-                unlighted_state = m->get_effect();
             } else {
-                SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << u << '\'');
-                unlighted_state = lighted_state;
+                material = m;
+                // set material states (lighted & unlighted)
+                lighted_state = material->get_effect();
+                newmat.append(".unlighted");
+
+                m = matlib->find(newmat);
+                if (m) {
+                    unlighted_state = m->get_effect();
+                } else {
+                    SG_LOG(SG_TERRAIN, SG_ALERT, SIGN "ignoring unknown material `" << newmat << '\'');
+                    unlighted_state = lighted_state;
+                }
             }
-            newmat = "";
+            newmat.clear();
         }
 
+        // This can only happen if the default material is missing.
+        // Error has been already logged in the block above.
+        if (!material) continue;
         SGMaterialGlyph *glyph = material->get_glyph(name);
         if (!glyph) {
             SG_LOG( SG_TERRAIN, SG_ALERT, SIGN "unsupported glyph `" << *s << '\'');