simplify OpenRWops, fix error handling
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user