mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-22 01:39:57 +00:00
WINTERMUTE: Fix almost all of the memory leaks that were left.
This commit is contained in:
parent
ae714dc076
commit
e49b43f7a9
@ -763,6 +763,15 @@ CBFileEntry *CBFileManager::getPackageEntry(const Common::String &Filename) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CBFileManager::hasFile(const Common::String &filename) {
|
||||
//TODO: Do this in a much simpler fashion
|
||||
Common::SeekableReadStream *stream = openFile(filename, true, false);
|
||||
if (!stream) {
|
||||
return false;
|
||||
}
|
||||
delete stream;
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
Common::SeekableReadStream *CBFileManager::openFile(const Common::String &filename, bool AbsPathWarning, bool keepTrackOf) {
|
||||
@ -801,16 +810,18 @@ HRESULT CBFileManager::closeFile(Common::SeekableReadStream *File) {
|
||||
Common::SeekableReadStream *CBFileManager::openFileRaw(const Common::String &Filename) {
|
||||
restoreCurrentDir();
|
||||
|
||||
Common::SeekableReadStream *ret = NULL;
|
||||
|
||||
if (scumm_strnicmp(Filename.c_str(), "savegame:", 9) == 0) {
|
||||
CBSaveThumbFile *SaveThumbFile = new CBSaveThumbFile(Game);
|
||||
if (SUCCEEDED(SaveThumbFile->open(Filename))) return SaveThumbFile->getMemStream();
|
||||
else {
|
||||
delete SaveThumbFile;
|
||||
return NULL;
|
||||
}
|
||||
if (SUCCEEDED(SaveThumbFile->open(Filename))) {
|
||||
ret = SaveThumbFile->getMemStream();
|
||||
}
|
||||
delete SaveThumbFile;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *ret = NULL;
|
||||
|
||||
|
||||
ret = openDiskFile(Filename, this);
|
||||
if (ret) return ret;
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
bool getFullPath(const Common::String &filename, char *fullname);
|
||||
Common::SeekableReadStream *openFileRaw(const Common::String &filename);
|
||||
HRESULT closeFile(Common::SeekableReadStream *File);
|
||||
bool hasFile(const Common::String &filename);
|
||||
Common::SeekableReadStream *openFile(const Common::String &filename, bool absPathWarning = true, bool keepTrackOf = true);
|
||||
CBFileEntry *getPackageEntry(const Common::String &filename);
|
||||
Common::File *openSingleFile(const Common::String &name);
|
||||
|
@ -270,7 +270,7 @@ HRESULT CBPersistMgr::readHeader(const Common::String &filename) {
|
||||
|
||||
if (Magic == SAVE_MAGIC_2) {
|
||||
_savedVerBuild = (byte)getDWORD();
|
||||
_savedName = getString();
|
||||
_savedName = getStringObj();
|
||||
|
||||
// load thumbnail
|
||||
_thumbnailDataSize = getDWORD();
|
||||
@ -393,6 +393,21 @@ void CBPersistMgr::putString(const Common::String &val) {
|
||||
}
|
||||
}
|
||||
|
||||
Common::String CBPersistMgr::getStringObj() {
|
||||
uint32 len = _loadStream->readUint32LE();
|
||||
char *ret = new char[len + 1];
|
||||
_loadStream->read(ret, len);
|
||||
ret[len] = '\0';
|
||||
delete[] ret;
|
||||
|
||||
Common::String retString = ret;
|
||||
|
||||
if (ret == "(null)") {
|
||||
retString = "";
|
||||
}
|
||||
|
||||
return retString;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char *CBPersistMgr::getString() {
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
uint32 getDWORD();
|
||||
void putDWORD(uint32 val);
|
||||
char *getString();
|
||||
Common::String getStringObj();
|
||||
void putString(const Common::String &val);
|
||||
float getFloat();
|
||||
void putFloat(float val);
|
||||
|
@ -101,19 +101,18 @@ HRESULT CBSoundBuffer::loadFromFile(const char *Filename, bool ForceReload) {
|
||||
_stream = NULL;
|
||||
}
|
||||
#endif
|
||||
delete _stream;
|
||||
_stream = NULL;
|
||||
// If we already had a file, delete it.
|
||||
delete _file;
|
||||
|
||||
if (_file) Game->_fileManager->closeFile(_file);
|
||||
|
||||
_file = Game->_fileManager->openFile(Filename);
|
||||
// Load a file, but avoid having the File-manager handle the disposal of it.
|
||||
_file = Game->_fileManager->openFile(Filename, true, false);
|
||||
if (!_file) {
|
||||
Game->LOG(0, "Error opening sound file '%s'", Filename);
|
||||
return E_FAIL;
|
||||
}
|
||||
Common::String strFilename(Filename);
|
||||
if (strFilename.hasSuffix(".ogg")) {
|
||||
_stream = Audio::makeVorbisStream(_file, DisposeAfterUse::NO);
|
||||
_stream = Audio::makeVorbisStream(_file, DisposeAfterUse::YES);
|
||||
} else if (strFilename.hasSuffix(".wav")) {
|
||||
warning("BSoundBuffer::LoadFromFile - WAVE not supported yet for %s", Filename);
|
||||
//_stream = Audio::makeWAVStream(_file, DisposeAfterUse::NO);
|
||||
@ -193,10 +192,10 @@ HRESULT CBSoundBuffer::play(bool looping, uint32 startSample) {
|
||||
}
|
||||
if (_stream) {
|
||||
if (looping) {
|
||||
Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_stream, 0, DisposeAfterUse::NO);
|
||||
Audio::AudioStream *loopStream = new Audio::LoopingAudioStream(_stream, 0, DisposeAfterUse::YES);
|
||||
g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, loopStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES);
|
||||
} else {
|
||||
g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, _stream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
||||
g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, _handle, _stream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES);
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
|
@ -138,10 +138,8 @@ CBSoundBuffer *CBSoundMgr::addSound(const char *Filename, TSoundType Type, bool
|
||||
AnsiString name = PathUtil::GetFileNameWithoutExtension(Filename);
|
||||
|
||||
AnsiString newFile = PathUtil::Combine(path, name + "ogg");
|
||||
Common::SeekableReadStream *file = Game->_fileManager->openFile(newFile.c_str());
|
||||
if (file) {
|
||||
if (Game->_fileManager->hasFile(newFile)) {
|
||||
Filename = newFile.c_str();
|
||||
Game->_fileManager->closeFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,11 +70,10 @@ CBSurfaceSDL::~CBSurfaceSDL() {
|
||||
delete _scaledSurface;
|
||||
_scaledSurface = NULL;
|
||||
}
|
||||
#if 0
|
||||
if (_texture) SDL_DestroyTexture(_texture);
|
||||
|
||||
delete[] _alphaMask;
|
||||
_alphaMask = NULL;
|
||||
#endif
|
||||
|
||||
Game->AddMem(-_width * _height * 4);
|
||||
}
|
||||
|
||||
@ -151,6 +150,7 @@ HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red,
|
||||
|
||||
// convert 32-bit BMPs to 24-bit or they appear totally transparent (does any app actually write alpha in BMP properly?)
|
||||
// Well, actually, we don't convert via 24-bit as the color-key application overwrites the Alpha-channel anyhow.
|
||||
delete _surface;
|
||||
if (strFileName.hasSuffix(".bmp") && image->getSurface()->format.bytesPerPixel == 4) {
|
||||
_surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
|
||||
TransparentSurface trans(*_surface);
|
||||
|
@ -105,20 +105,17 @@ CBSurface *CBSurfaceStorage::addSurface(const char *Filename, bool default_ck, b
|
||||
}
|
||||
}
|
||||
|
||||
Common::SeekableReadStream *File = Game->_fileManager->openFile(Filename);
|
||||
if (!File) {
|
||||
if (!Game->_fileManager->hasFile(Filename)) {
|
||||
if (Filename) Game->LOG(0, "Missing image: '%s'", Filename);
|
||||
if (Game->_dEBUG_DebugMode)
|
||||
return addSurface("invalid_debug.bmp", default_ck, ck_red, ck_green, ck_blue, LifeTime, KeepLoaded);
|
||||
else
|
||||
return addSurface("invalid.bmp", default_ck, ck_red, ck_green, ck_blue, LifeTime, KeepLoaded);
|
||||
} else Game->_fileManager->closeFile(File);
|
||||
|
||||
}
|
||||
|
||||
CBSurface *surface;
|
||||
surface = new CBSurfaceSDL(Game);
|
||||
|
||||
|
||||
if (!surface) return NULL;
|
||||
|
||||
if (FAILED(surface->create(Filename, default_ck, ck_red, ck_green, ck_blue, LifeTime, KeepLoaded))) {
|
||||
|
@ -424,6 +424,8 @@ void CScScript::cleanup() {
|
||||
_waitScript = NULL;
|
||||
|
||||
_parentScript = NULL; // ref only
|
||||
|
||||
delete _scriptStream;
|
||||
}
|
||||
|
||||
|
||||
|
@ -214,7 +214,7 @@ HRESULT CSysClassRegistry::loadTable(CBGame *Game, CBPersistMgr *persistMgr) {
|
||||
Game->DisplayContentSimple();
|
||||
Game->_renderer->flip();
|
||||
|
||||
char *className = persistMgr->getString();
|
||||
Common::String className = persistMgr->getStringObj();
|
||||
NameMap::iterator mapIt = _nameMap.find(className);
|
||||
if (mapIt != _nameMap.end())(*mapIt)._value->loadTable(Game, persistMgr);
|
||||
}
|
||||
|
@ -108,6 +108,11 @@ CVidTheoraPlayer::~CVidTheoraPlayer(void) {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CVidTheoraPlayer::cleanup() {
|
||||
if (_file) {
|
||||
Game->_fileManager->closeFile(_file);
|
||||
_file = NULL;
|
||||
}
|
||||
|
||||
_surface.free();
|
||||
delete _theoraDecoder;
|
||||
_theoraDecoder = NULL;
|
||||
|
@ -456,7 +456,7 @@ bool TheoraDecoder::queueAudio() {
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
flags |= Audio::FLAG_LITTLE_ENDIAN;
|
||||
#endif
|
||||
_audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, flags);
|
||||
_audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::YES, flags);
|
||||
|
||||
// The audio mixer is now responsible for the old audio buffer.
|
||||
// We need to create a new one.
|
||||
|
Loading…
Reference in New Issue
Block a user