From 955fd88a36806ffad891c54baebce0b0cdf2664a Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 9 Aug 2015 00:00:40 -0400 Subject: [PATCH] Fixed issue when attempting to save battery file while closing emu --- Core/BaseMapper.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 331a87f0..79a40f84 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -28,6 +28,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat { private: MirroringType _mirroringType; + string _batteryFilename; protected: uint8_t* _prgRom; @@ -177,7 +178,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat void LoadBattery() { - ifstream batteryFile(GetBatteryFilename(), ios::in | ios::binary); + ifstream batteryFile(_batteryFilename, ios::in | ios::binary); if(batteryFile) { batteryFile.read((char*)_saveRam, _saveRamSize); @@ -191,7 +192,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat void SaveBattery() { - ofstream batteryFile(GetBatteryFilename(), ios::out | ios::binary); + ofstream batteryFile(_batteryFilename, ios::out | ios::binary); if(batteryFile) { batteryFile.write((char*)_saveRam, _saveRamSize); @@ -256,6 +257,8 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat public: void Initialize(ROMLoader &romLoader) { + _romFilename = romLoader.GetFilename(); + _batteryFilename = GetBatteryFilename(); _saveRamSize = GetSaveRamSize(); //Needed because we need to call SaveBattery() in the destructor (and calling virtual functions in the destructor doesn't work correctly) _allowRegisterRead = AllowRegisterRead(); @@ -270,7 +273,6 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat _chrSize = romLoader.GetCHRSize(); _hasBattery = romLoader.HasBattery(); _isPalRom = romLoader.IsPalRom(); - _romFilename = romLoader.GetFilename(); _saveRam = new uint8_t[_saveRamSize]; _workRam = new uint8_t[GetWorkRamSize()];