If loading an image fails, try loading "images/engine/missing.png" first before faili...
authorChristoph Sommer <mail@christoph-sommer.de>
Mon, 23 Jun 2008 18:33:17 +0000 (18:33 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Mon, 23 Jun 2008 18:33:17 +0000 (18:33 +0000)
SVN-Revision: 5618

data/images/engine/missing.png [new file with mode: 0644]
src/video/texture_manager.cpp

diff --git a/data/images/engine/missing.png b/data/images/engine/missing.png
new file mode 100644 (file)
index 0000000..79f6cb8
Binary files /dev/null and b/data/images/engine/missing.png differ
index 4bdece7..005d2a9 100644 (file)
@@ -95,25 +95,39 @@ TextureManager::remove_texture(GL::Texture* texture)
 Texture*
 TextureManager::create_image_texture(const std::string& filename)
 {
-  SDL_Surface* image = IMG_Load_RW(get_physfs_SDLRWops(filename), 1);
-  if(image == 0) {
-    std::ostringstream msg;
-    msg << "Couldn't load image '" << filename << "' :" << SDL_GetError();
-    throw std::runtime_error(msg.str());
-  }
-
-  Texture* result = 0;
   try {
-    result = new_texture(image);
-    result->set_filename(filename);
-  } catch(...) {
-    delete result;
+
+    SDL_Surface* image = IMG_Load_RW(get_physfs_SDLRWops(filename), 1);
+    if(image == 0) {
+      std::ostringstream msg;
+      msg << "Couldn't load image '" << filename << "' :" << SDL_GetError();
+      throw std::runtime_error(msg.str());
+    }
+
+    Texture* result = 0;
+    try {
+      result = new_texture(image);
+      result->set_filename(filename);
+    } catch(...) {
+      delete result;
+      SDL_FreeSurface(image);
+      throw;
+    }
+
     SDL_FreeSurface(image);
-    throw;
+    return result;
+
+  } catch (const std::runtime_error& err) {
+    // on error, try loading placeholder file
+    const std::string dummy_texture_fname = "ximages/engine/missing.png";
+    if (filename != dummy_texture_fname) {
+      Texture* tex = create_image_texture(dummy_texture_fname);
+      log_warning << "Couldn't load texture '" << filename << "': " << err.what() << std::endl;
+      return tex;
+    }
+    // if this also failed, escalate error
+    throw err;
   }
-
-  SDL_FreeSurface(image);
-  return result;
 }
 
 #ifdef HAVE_OPENGL