Loaders: Prevent errors on 0 byte reads.

Was happening when opening an http:// GE frame dump.
This commit is contained in:
Unknown W. Brackets 2021-01-31 09:21:40 -08:00
parent 8205f9b6f2
commit a20c972d55
2 changed files with 10 additions and 0 deletions

View file

@ -98,6 +98,10 @@ size_t DiskCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data,
// While in case the cache size is too small for the entire read.
while (readSize < bytes) {
readSize += cache_->SaveIntoCache(backend_, absolutePos + readSize, bytes - readSize, (u8 *)data + readSize, flags);
// We're done, nothing more to read.
if (readSize == bytes) {
break;
}
// If there are already-cached blocks afterward, we have to read them.
size_t bytesFromCache = cache_->ReadFromCache(absolutePos + readSize, bytes - readSize, (u8 *)data + readSize);
readSize += bytesFromCache;
@ -441,6 +445,9 @@ bool DiskCachingFileLoaderCache::ReadBlockData(u8 *dest, BlockInfo &info, size_t
if (!f_) {
return false;
}
if (size == 0) {
return true;
}
s64 blockOffset = GetBlockOffset(info.block);
// Before we read, make sure the buffers are flushed.

View file

@ -119,6 +119,9 @@ std::string LocalFileLoader::Path() const {
}
size_t LocalFileLoader::ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags) {
if (bytes == 0)
return 0;
#if PPSSPP_PLATFORM(SWITCH)
// Toolchain has no fancy IO API. We must lock.
std::lock_guard<std::mutex> guard(readLock_);