Skip to content

Commit

Permalink
SaveState: Initialize some memory that is saved.
Browse files Browse the repository at this point in the history
At the very least, will help them compress better.  Also good not to leak
random memory.
  • Loading branch information
unknownbrackets committed Jun 23, 2018
1 parent 3090360 commit fd8a061
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Common/ChunkFile.cpp
Expand Up @@ -300,15 +300,15 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
}

// Create header
SChunkHeader header;
SChunkHeader header{};
header.Compress = compressed_buffer ? 1 : 0;
header.Revision = REVISION_CURRENT;
header.ExpectedSize = (u32)write_len;
header.UncompressedSize = (u32)sz;
truncate_cpy(header.GitVersion, gitVersion);

// Setup the fixed-length title.
char titleFixed[128];
char titleFixed[128]{};
truncate_cpy(titleFixed, title.c_str());

// Now let's start writing out the file...
Expand Down
2 changes: 2 additions & 0 deletions Common/FixedSizeQueue.h
Expand Up @@ -46,6 +46,8 @@ class FixedSizeQueue {
head_ = 0;
tail_ = 0;
count_ = 0;
// Not entirely necessary, but keeps things clean.
memset(storage_, 0, sizeof(T) * N);
}

void push(T t) {
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/__sceAudio.cpp
Expand Up @@ -160,6 +160,7 @@ void __AudioDoState(PointerWrap &p) {

p.Do(mixFrequency);

// TODO: This never happens because maxVer=1.
if (s >= 2) {
resampler.DoState(p);
} else {
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceKernelInterrupt.cpp
Expand Up @@ -317,6 +317,7 @@ void InterruptState::restore()

void InterruptState::clear()
{
savedCpu.reset();
}

// http://forums.ps2dev.org/viewtopic.php?t=5687
Expand Down
4 changes: 3 additions & 1 deletion Core/HLE/sceKernelThread.cpp
Expand Up @@ -544,7 +544,7 @@ class Thread : public KernelObject
p.Do(currentMipscallId);
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);

if (s <= 3)
Expand Down Expand Up @@ -1824,6 +1824,8 @@ void ThreadContext::reset()
fcr31 = 0x00000e00;
hi = 0xDEADBEEF;
lo = 0xDEADBEEF;
// Just for a clean state.
other[5] = 0;
}

void __KernelResetThread(Thread *t, int lowestPriority)
Expand Down
22 changes: 11 additions & 11 deletions Core/HW/SasAudio.h
Expand Up @@ -111,21 +111,21 @@ class VagDecoder {

private:
s16 samples[28];
int curSample;
int curSample = 0;

u32 data_;
u32 read_;
int curBlock_;
int loopStartBlock_;
int numBlocks_;
u32 data_ = 0;
u32 read_ = 0;
int curBlock_ = -1;
int loopStartBlock_ = -1;
int numBlocks_ = 0;

// rolling state. start at 0, should probably reset to 0 on loops?
int s_1;
int s_2;
int s_1 = 0;
int s_2 = 0;

bool loopEnabled_;
bool loopAtNextBlock_;
bool end_;
bool loopEnabled_ = false;
bool loopAtNextBlock_ = false;
bool end_ = false;
};

class SasAtrac3 {
Expand Down
5 changes: 5 additions & 0 deletions Core/Util/BlockAllocator.cpp
Expand Up @@ -501,5 +501,10 @@ void BlockAllocator::Block::DoState(PointerWrap &p)
p.Do(start);
p.Do(size);
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));
}
4 changes: 2 additions & 2 deletions GPU/GPUCommon.h
Expand Up @@ -319,8 +319,8 @@ class GPUCommon : public GPUInterface, public GPUDebugInterface {
DisplayList *currentList;
DisplayListQueue dlQueue;

bool interruptRunning;
GPURunState gpuState;
bool interruptRunning = false;
GPURunState gpuState = GPUSTATE_RUNNING;
bool isbreak;
u64 drawCompleteTicks;
u64 busyTicks;
Expand Down

0 comments on commit fd8a061

Please sign in to comment.