Properly free RWops associated with Font objects

This commit is contained in:
Jonas Kulla 2013-09-10 04:18:58 +02:00
parent 80d0b33dda
commit d1bfc1e50c
3 changed files with 19 additions and 4 deletions

View File

@ -711,11 +711,21 @@ static int SDL_RWopsClose(SDL_RWops *ops)
return (result != 0) ? 0 : -1; return (result != 0) ? 0 : -1;
} }
static int SDL_RWopsCloseFree(SDL_RWops *ops)
{
int result = SDL_RWopsClose(ops);
SDL_FreeRW(ops);
return result;
}
const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN+10; const Uint32 SDL_RWOPS_PHYSFS = SDL_RWOPS_UNKNOWN+10;
void FileSystem::openRead(SDL_RWops &ops, void FileSystem::openRead(SDL_RWops &ops,
const char *filename, const char *filename,
FileType type) FileType type,
bool freeOnClose)
{ {
PHYSFS_File *handle = openReadInt(filename, type); PHYSFS_File *handle = openReadInt(filename, type);
@ -723,7 +733,11 @@ void FileSystem::openRead(SDL_RWops &ops,
ops.seek = SDL_RWopsSeek; ops.seek = SDL_RWopsSeek;
ops.read = SDL_RWopsRead; ops.read = SDL_RWopsRead;
ops.write = SDL_RWopsWrite; ops.write = SDL_RWopsWrite;
ops.close = SDL_RWopsClose;
if (freeOnClose)
ops.close = SDL_RWopsCloseFree;
else
ops.close = SDL_RWopsClose;
ops.type = SDL_RWOPS_PHYSFS; ops.type = SDL_RWOPS_PHYSFS;
ops.hidden.unknown.data1 = handle; ops.hidden.unknown.data1 = handle;

View File

@ -71,7 +71,8 @@ public:
void openRead(SDL_RWops &ops, void openRead(SDL_RWops &ops,
const char *filename, const char *filename,
FileType type = Undefined); FileType type = Undefined,
bool freeOnClose = false);
bool exists(const char *filename, bool exists(const char *filename,
FileType type = Undefined); FileType type = Undefined);

View File

@ -107,7 +107,7 @@ _TTF_Font *FontPool::request(const char *filename,
else else
{ {
ops = SDL_AllocRW(); ops = SDL_AllocRW();
gState->fileSystem().openRead(*ops, path.constData(), FileSystem::Font); gState->fileSystem().openRead(*ops, path.constData(), FileSystem::Font, true);
} }
// FIXME 0.9 is guesswork at this point // FIXME 0.9 is guesswork at this point