Proper fix for waterfall tiles
[supertux.git] / src / video / texture_manager.cpp
index e7c392f..f334275 100644 (file)
@@ -149,6 +149,12 @@ TextureManager::create_image_texture_raw(const std::string& filename, const Rect
     m_surfaces[filename] = image;
   }
 
+  SDL_PixelFormat* format = image->format;
+  if(format->Rmask == 0 && format->Gmask == 0 && format->Bmask == 0 && format->Amask == 0) {
+    log_warning << "Wrong surface format for image " << filename << ". Compensating." << std::endl;
+    image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA8888, 0);
+  }
+
   SDLSurfacePtr subimage(SDL_CreateRGBSurfaceFrom(static_cast<uint8_t*>(image->pixels) +
                                                   rect.top * image->pitch +
                                                   rect.left * image->format->BytesPerPixel,
@@ -259,7 +265,11 @@ TextureManager::save_textures()
   for(ImageTextures::iterator i = m_image_textures.begin();
       i != m_image_textures.end(); ++i)
   {
-    save_texture(dynamic_cast<GLTexture*>(i->second.lock().get()));
+    GLTexture* texture = dynamic_cast<GLTexture*>(i->second.lock().get());
+    if(texture == NULL)
+      continue;
+
+    save_texture(texture);
   }
 }