fixup 43c54fc75a09d60f8feeb83205a3a02b519a7025, save png segfaults

Our filesystem functions are for reading, not writing.
This commit is contained in:
Chris Beck 2014-11-02 21:33:36 -05:00
parent c25de4bd87
commit d208c72998
2 changed files with 6 additions and 4 deletions

View File

@ -13,10 +13,10 @@
* Returns 0 success or -1 on failure, the error message is then retrievable
* via SDL_GetError().
*/
//#define SDL_SavePNG(surface, file)
// SDL_SavePNG_RW(surface, SDL_RWFromFile(file, "wb"), 1)
#define SDL_SavePNG(surface, file) \
SDL_SavePNG_RW(surface, SDL_RWFromFile(file, "wb"), 1)
//
//I delete this ^ because we should always use our own filesystem functions
//TODO: filesystem::load_RWops is only for reading, would like a writing version also
/*
* Save an SDL_Surface as a PNG file, using writable RWops.

View File

@ -1255,7 +1255,9 @@ void save_image(const surface & surf, const std::string & filename)
LOG_DP << "Writing a png image to " << filename << std::endl;
//safest way,
SDL_Surface *tmp = SDL_PNGFormatAlpha(surf.get());
SDL_SavePNG_RW(tmp, filesystem::load_RWops(filename), 1); //1 means to close the file (RWops) when we finish
SDL_SavePNG(tmp, filename.c_str());
//SDL_SavePNG_RW(tmp, filesystem::load_RWops(filename), 1); //1 means to close the file (RWops) when we finish
//^ This doesn't work, load_RWops is only for reading not writing
SDL_FreeSurface(tmp);
return ;
}