Fix infinite loop when reading dirty buffers with direct mem

The code didn't account for interval Queries returning zero when reaching the end.
This commit is contained in:
Billy Laws 2023-03-15 17:53:35 +00:00
parent 0b551e04db
commit 1f0d297221

View File

@ -312,12 +312,15 @@ namespace skyline::gpu {
RefreshGpuWritesActiveDirect(true, flushHostCallback); RefreshGpuWritesActiveDirect(true, flushHostCallback);
if (directTrackedShadowActive && RefreshGpuReadsActiveDirect()) { if (directTrackedShadowActive && RefreshGpuReadsActiveDirect()) {
size_t curOffset{offset}; size_t dstOffset{};
while (curOffset != data.size() + offset) { while (dstOffset != data.size()) {
auto result{directTrackedWrites.Query(curOffset)}; auto srcOffset{dstOffset + offset};
auto dstRemaining{data.size() - dstOffset};
auto result{directTrackedWrites.Query(srcOffset)};
auto size{result.size ? std::min(result.size, dstRemaining) : dstRemaining};
auto srcData{result.enclosed ? directTrackedShadow.data() : mirror.data()}; auto srcData{result.enclosed ? directTrackedShadow.data() : mirror.data()};
std::memcpy(data.data() + curOffset - offset, srcData + curOffset, result.size); std::memcpy(data.data() + dstOffset, srcData + srcOffset, size);
curOffset += result.size; dstOffset += size;
} }
} else [[likely]] { } else [[likely]] {
std::memcpy(data.data(), mirror.data() + offset, data.size()); std::memcpy(data.data(), mirror.data() + offset, data.size());