diff --git a/Source/Core/Core/Src/PowerPC/PowerPC.cpp b/Source/Core/Core/Src/PowerPC/PowerPC.cpp index 11c7c928a3..31d3c46c91 100644 --- a/Source/Core/Core/Src/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/Src/PowerPC/PowerPC.cpp @@ -102,7 +102,7 @@ namespace PowerPC Interpreter::Init(); Jit64::Core::Init(); // ... but start as interpreter by default. - _mode = MODE_INTERPRETER; + mode = MODE_INTERPRETER; state = CPU_STEPPING; } diff --git a/Source/Core/Core/Src/State.cpp b/Source/Core/Core/Src/State.cpp index 4723726886..5a7035ee64 100644 --- a/Source/Core/Core/Src/State.cpp +++ b/Source/Core/Core/Src/State.cpp @@ -92,6 +92,10 @@ void SaveStateCallback(u64 userdata, int cyclesLate) if(bCompressed) { int chunks = sz / chunkSize, leftovers = sz % chunkSize; + //SANITY CHECK + if(((chunks * chunkSize) + leftovers) != sz) + PanicAlert("WTF %d != %d", ((chunks * chunkSize) + leftovers), sz); + strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; @@ -101,21 +105,23 @@ void SaveStateCallback(u64 userdata, int cyclesLate) strm.avail_in = chunkSize; memcpy(inbuf, buffer + i * chunkSize, chunkSize); strm.next_in = inbuf; - memcpy(outbuf, buffer + i * chunkSize, chunkSize); - strm.avail_out = chunkSize; - strm.next_out = outbuf; - deflate(&strm, Z_NO_FLUSH); - fwrite(outbuf, 1, chunkSize - strm.avail_out, f); + do { + strm.avail_out = chunkSize; + strm.next_out = outbuf; + deflate(&strm, Z_NO_FLUSH); + fwrite(outbuf, 1, chunkSize - strm.avail_out, f); + } while(strm.avail_out == 0); } strm.avail_in = leftovers; memcpy(inbuf, buffer + chunks * chunkSize, leftovers); strm.next_in = inbuf; - memcpy(outbuf, buffer + chunks * chunkSize, leftovers); - strm.avail_out = leftovers; - strm.next_out = outbuf; - deflate(&strm, Z_NO_FLUSH); - fwrite(outbuf, 1, leftovers - strm.avail_out, f); + do { + strm.avail_out = leftovers; + strm.next_out = outbuf; + deflate(&strm, Z_NO_FLUSH); + fwrite(outbuf, 1, leftovers - strm.avail_out, f); + } while(strm.avail_out == 0); (void)deflateEnd(&strm); } else @@ -162,10 +168,17 @@ void LoadStateCallback(u64 userdata, int cyclesLate) strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); + if (ret != Z_OK) + return; + int cnt = 0; do { - strm.avail_in = uInt(fread(inbuf, 1, chunkSize, f)); + strm.avail_in = fread(inbuf, 1, chunkSize, f); + if (ferror(f)) { + (void)inflateEnd(&strm); + return; + } if (strm.avail_in == 0) break; strm.next_in = inbuf; @@ -174,6 +187,14 @@ void LoadStateCallback(u64 userdata, int cyclesLate) strm.avail_out = chunkSize; strm.next_out = outbuf; ret = inflate(&strm, Z_NO_FLUSH); + _assert_(ret != Z_STREAM_ERROR); /* state not clobbered */ + switch (ret) { + case Z_NEED_DICT: + case Z_DATA_ERROR: + case Z_MEM_ERROR: + (void)inflateEnd(&strm); + return; + } int have = chunkSize - strm.avail_out; @@ -183,6 +204,8 @@ void LoadStateCallback(u64 userdata, int cyclesLate) } while (ret != Z_STREAM_END); (void)inflateEnd(&strm); + + PanicAlert("Got here, %d/%d", cnt, sz); } else { fseek(f, 0, SEEK_END); sz = ftell(f) - sizeof(int); @@ -197,7 +220,6 @@ void LoadStateCallback(u64 userdata, int cyclesLate) fclose(f); - u8 *ptr = buffer; PointerWrap p(&ptr, PointerWrap::MODE_READ); DoState(p); diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index d8d3f247da..4781a351c1 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -155,13 +155,13 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) // read the data and send it to the VideoPlugin u8 *uData = video_initialize.pGetMemoryPointer(_fifo.CPReadPointer); #ifdef _WIN32 - EnterCriticalSection(&fifo.sync); + EnterCriticalSection(&_fifo.sync); #endif _fifo.CPReadPointer += 32; Video_SendFifoData(uData); #ifdef _WIN32 InterlockedExchangeAdd((LONG*)&_fifo.CPReadWriteDistance, -32); - LeaveCriticalSection(&fifo.sync); + LeaveCriticalSection(&_fifo.sync); #endif // increase the ReadPtr if (_fifo.CPReadPointer >= _fifo.CPEnd)