Replaced Gnome.AppBar with a dialog (stored in .glade file)
[supertux.git] / src / video / texture_manager.cpp
index 976dad0..70b0e95 100644 (file)
@@ -118,15 +118,45 @@ TextureManager::create_image_texture(const std::string& filename)
     return result;
 
   } catch (const std::runtime_error& err) {
-    // on error, try loading placeholder file
     const std::string dummy_texture_fname = "images/engine/missing.png";
-    if (filename != dummy_texture_fname) {
+    if (filename == dummy_texture_fname) throw err;
+
+    // on error, try loading placeholder file
+    try {
+
       Texture* tex = create_image_texture(dummy_texture_fname);
-      log_warning << "Couldn't load texture '" << filename << "': " << err.what() << std::endl;
+      log_warning << "Couldn't load texture '" << filename << "' (now using dummy texture): " << err.what() << std::endl;
       return tex;
+
+    } catch (...) {
+
+      // on error (when loading placeholder), try using empty surface
+      try {
+
+       SDL_Surface* image = SDL_CreateRGBSurface(0, 1024, 1024, 8, 0, 0, 0, 0);
+       if(image == 0) {
+         throw err;
+       }
+
+       Texture* result = 0;
+       try {
+         result = new_texture(image);
+         result->set_filename("-dummy-texture-.png");
+       } catch(...) {
+         delete result;
+         SDL_FreeSurface(image);
+         throw err;
+       }
+
+       SDL_FreeSurface(image);
+        log_warning << "Couldn't load texture '" << filename << "' (now using empty one): " << err.what() << std::endl;
+       return result;
+
+      // on error (when trying to use empty surface), give up
+      } catch (const std::runtime_error& err) {
+       throw err;
+      }
     }
-    // if this also failed, escalate error
-    throw err;
   }
 }
 
@@ -159,6 +189,9 @@ TextureManager::save_texture(GL::Texture* texture)
   SavedTexture saved_texture;
   saved_texture.texture = texture;
   glBindTexture(GL_TEXTURE_2D, texture->get_handle());
+
+  //this doesn't work with OpenGL ES (but we don't need it on the GP2X anyway)
+#ifndef GL_VERSION_ES_CM_1_0
   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,
                            &saved_texture.width);
   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT,
@@ -179,6 +212,7 @@ TextureManager::save_texture(GL::Texture* texture)
 
   glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 saved_texture.pixels);
+#endif
 
   saved_textures.push_back(saved_texture);