SaveState: Initialize some memory that is saved.

At the very least, will help them compress better.  Also good not to leak
random memory.
This commit is contained in:
Unknown W. Brackets 2018-06-22 21:25:07 -07:00
parent 3090360692
commit fd8a0612fa
8 changed files with 27 additions and 16 deletions

View file

@ -300,7 +300,7 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
} }
// Create header // Create header
SChunkHeader header; SChunkHeader header{};
header.Compress = compressed_buffer ? 1 : 0; header.Compress = compressed_buffer ? 1 : 0;
header.Revision = REVISION_CURRENT; header.Revision = REVISION_CURRENT;
header.ExpectedSize = (u32)write_len; header.ExpectedSize = (u32)write_len;
@ -308,7 +308,7 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
truncate_cpy(header.GitVersion, gitVersion); truncate_cpy(header.GitVersion, gitVersion);
// Setup the fixed-length title. // Setup the fixed-length title.
char titleFixed[128]; char titleFixed[128]{};
truncate_cpy(titleFixed, title.c_str()); truncate_cpy(titleFixed, title.c_str());
// Now let's start writing out the file... // Now let's start writing out the file...

View file

@ -46,6 +46,8 @@ public:
head_ = 0; head_ = 0;
tail_ = 0; tail_ = 0;
count_ = 0; count_ = 0;
// Not entirely necessary, but keeps things clean.
memset(storage_, 0, sizeof(T) * N);
} }
void push(T t) { void push(T t) {

View file

@ -160,6 +160,7 @@ void __AudioDoState(PointerWrap &p) {
p.Do(mixFrequency); p.Do(mixFrequency);
// TODO: This never happens because maxVer=1.
if (s >= 2) { if (s >= 2) {
resampler.DoState(p); resampler.DoState(p);
} else { } else {

View file

@ -317,6 +317,7 @@ void InterruptState::restore()
void InterruptState::clear() void InterruptState::clear()
{ {
savedCpu.reset();
} }
// http://forums.ps2dev.org/viewtopic.php?t=5687 // http://forums.ps2dev.org/viewtopic.php?t=5687

View file

@ -544,7 +544,7 @@ public:
p.Do(currentMipscallId); p.Do(currentMipscallId);
p.Do(currentCallbackId); p.Do(currentCallbackId);
// TODO: How do I "version" adding a DoState method to ThreadContext? // TODO: If we want to "version" a DoState method here, we can just use minVer = 0.
p.Do(context); p.Do(context);
if (s <= 3) if (s <= 3)
@ -1824,6 +1824,8 @@ void ThreadContext::reset()
fcr31 = 0x00000e00; fcr31 = 0x00000e00;
hi = 0xDEADBEEF; hi = 0xDEADBEEF;
lo = 0xDEADBEEF; lo = 0xDEADBEEF;
// Just for a clean state.
other[5] = 0;
} }
void __KernelResetThread(Thread *t, int lowestPriority) void __KernelResetThread(Thread *t, int lowestPriority)

View file

@ -111,21 +111,21 @@ public:
private: private:
s16 samples[28]; s16 samples[28];
int curSample; int curSample = 0;
u32 data_; u32 data_ = 0;
u32 read_; u32 read_ = 0;
int curBlock_; int curBlock_ = -1;
int loopStartBlock_; int loopStartBlock_ = -1;
int numBlocks_; int numBlocks_ = 0;
// rolling state. start at 0, should probably reset to 0 on loops? // rolling state. start at 0, should probably reset to 0 on loops?
int s_1; int s_1 = 0;
int s_2; int s_2 = 0;
bool loopEnabled_; bool loopEnabled_ = false;
bool loopAtNextBlock_; bool loopAtNextBlock_ = false;
bool end_; bool end_ = false;
}; };
class SasAtrac3 { class SasAtrac3 {

View file

@ -501,5 +501,10 @@ void BlockAllocator::Block::DoState(PointerWrap &p)
p.Do(start); p.Do(start);
p.Do(size); p.Do(size);
p.Do(taken); p.Do(taken);
// Since we use truncate_cpy, the empty space is not zeroed. Zero it now.
// This avoids saving uninitialized memory.
size_t tagLen = strlen(tag);
if (tagLen != sizeof(tag))
memset(tag + tagLen, 0, sizeof(tag) - tagLen);
p.DoArray(tag, sizeof(tag)); p.DoArray(tag, sizeof(tag));
} }

View file

@ -319,8 +319,8 @@ protected:
DisplayList *currentList; DisplayList *currentList;
DisplayListQueue dlQueue; DisplayListQueue dlQueue;
bool interruptRunning; bool interruptRunning = false;
GPURunState gpuState; GPURunState gpuState = GPUSTATE_RUNNING;
bool isbreak; bool isbreak;
u64 drawCompleteTicks; u64 drawCompleteTicks;
u64 busyTicks; u64 busyTicks;