From: Christoph Sommer Date: Mon, 23 Jun 2008 18:33:17 +0000 (+0000) Subject: If loading an image fails, try loading "images/engine/missing.png" first before faili... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=12f8a446a90eecce73e97d84a1b08e4da218d1f4;p=supertux.git If loading an image fails, try loading "images/engine/missing.png" first before failing hard SVN-Revision: 5618 --- diff --git a/data/images/engine/missing.png b/data/images/engine/missing.png new file mode 100644 index 000000000..79f6cb843 Binary files /dev/null and b/data/images/engine/missing.png differ diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index 4bdece75a..005d2a998 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -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