diff --git a/stepmania/src/RageSurface_Load.cpp b/stepmania/src/RageSurface_Load.cpp index 9645612675..ae952cbae8 100644 --- a/stepmania/src/RageSurface_Load.cpp +++ b/stepmania/src/RageSurface_Load.cpp @@ -4,6 +4,7 @@ #include "RageSurface_Load_JPEG.h" #include "RageSurface_Load_GIF.h" #include "RageUtil.h" +#include "RageFile.h" SDL_Surface *RageSurface::LoadFile( const CString &sPath ) { @@ -19,17 +20,17 @@ SDL_Surface *RageSurface::LoadFile( const CString &sPath ) ret = RageSurface_Load_JPEG( sPath, error ); else if( !ext.CompareNoCase("bmp") ) { - SDL_RWops *rw = OpenRWops( sPath, false ); - if( rw == NULL ) + RageFile f; + if( !f.Open(sPath) ) { - /* XXX */ - SDL_SetError( "fail" ); + SDL_SetError( "%s", f.GetError() ); return NULL; } - ret = SDL_LoadBMP_RW( rw, false ); - SDL_RWclose( rw ); - SDL_FreeRW( rw ); + SDL_RWops rw; + OpenRWops( &rw, &f ); + ret = SDL_LoadBMP_RW( &rw, false ); + SDL_RWclose( &rw ); if( ret ) mySDL_FixupPalettedAlpha( ret ); diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index 7b686f9dd1..e3a36dfcee 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -1018,30 +1018,16 @@ int RWRageFile_Write( struct SDL_RWops *context, const void *ptr, int size, int /* Close and free an allocated SDL_FSops structure */ int RWRageFile_Close(struct SDL_RWops *context) { - RageFile *f = (RageFile *) context->hidden.unknown.data1; - delete f; return 0; } -SDL_RWops *OpenRWops( const CString &sPath, bool Write ) +void OpenRWops( SDL_RWops *rw, RageFile *f ) { - RageFile *f = new RageFile; - if( !f->Open(sPath, Write? RageFile::WRITE:RageFile::READ) ) - { - LOG->Trace("Couldn't open %s: %s", sPath.c_str(), f->GetError().c_str() ); - delete f; - return NULL; - } - - SDL_RWops *rw = SDL_AllocRW(); - ASSERT( rw ); rw->hidden.unknown.data1 = f; rw->seek = RWRageFile_Seek; rw->read = RWRageFile_Read; rw->write = RWRageFile_Write; rw->close = RWRageFile_Close; - - return rw; } struct RWString diff --git a/stepmania/src/SDL_utils.h b/stepmania/src/SDL_utils.h index 12ab894ee1..5908f18b11 100644 --- a/stepmania/src/SDL_utils.h +++ b/stepmania/src/SDL_utils.h @@ -84,7 +84,8 @@ void mySDL_FixupPalettedAlpha( SDL_Surface *img ); void mySDL_AddColorKey( SDL_Surface *img, Uint32 color ); void ApplyHotPinkColorKey( SDL_Surface *&img ); -SDL_RWops *OpenRWops( const CString &sPath, bool Write=false ); +class RageFile; +void OpenRWops( SDL_RWops *rw, RageFile *f ); SDL_RWops *OpenRWops( CString &sBuf ); SDL_Surface *mySDL_MakeDummySurface( int height, int width );