From 12f8a446a90eecce73e97d84a1b08e4da218d1f4 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 23 Jun 2008 18:33:17 +0000 Subject: [PATCH] If loading an image fails, try loading "images/engine/missing.png" first before failing hard SVN-Revision: 5618 --- data/images/engine/missing.png | Bin 0 -> 1614 bytes src/video/texture_manager.cpp | 46 +++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 data/images/engine/missing.png diff --git a/data/images/engine/missing.png b/data/images/engine/missing.png new file mode 100644 index 0000000000000000000000000000000000000000..79f6cb8434a30d8cd244cd062e0c3316018e4680 GIT binary patch literal 1614 zcmeAS@N?(olHy`uVBq!ia0y~yU;#2&7?_xW6jSkG0U*U#9OUlAu;OkH}&M25w;xW@MN(M*=9wUgGKN%6@}Q zTu53=R^ql9P)N4KHKN2hKQ}iuuY|$5C^fMpHASI3vm`?yBqLS9-P1SVeTr%x0|V3HA_Xg4_a7 z2m`@^dA}KN7th-Vbq?}szQLx0iu+lgb~vP7nnE5 zLw#ML53{V{H{&O$MQ4~xpt=j}55SCku(yE^D*BEc)Bg$Q|2Dj}^uG^vdMY@v0M$E) zJN$!aYp8@9VB3)OE*%zJ9Lx$(b9XUdy5I%l4SuL!_lUy+`@mm@pHPdQFT{RBL(FxMWPk?71y;=T;=sRP*6*9J;5tMgxqNemy7fIPBD%3e);o4$W8lqB`3<(u zUsglRC6r$R&i;i5S0eu8!th%WVrIj4CPZ{&=2u{TgBwX82EN_lzcKIg7h8zA0R-~P zif47O;38CF5SzJy`3+_y1A!Q*e#f43zVeqG#H|_x@=HjuJuJ8!B=9E}Vly`|zrlset_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 -- 2.11.0