From a7b4fe91675a792963c486bed8f03de0629724d4 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 27 Apr 2020 13:03:47 +0100 Subject: [PATCH] Don't clamp length against buffer size after applying offset * If we have a given view length that fits in the buffer, we shouldn't apply the offset before clamping. Instead we apply the offset on the buffer length if that's what we're using as our size. --- qrenderdoc/Windows/BufferViewer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Windows/BufferViewer.cpp b/qrenderdoc/Windows/BufferViewer.cpp index dea776666..7af117950 100644 --- a/qrenderdoc/Windows/BufferViewer.cpp +++ b/qrenderdoc/Windows/BufferViewer.cpp @@ -2494,10 +2494,17 @@ void BufferViewer::OnEventChanged(uint32_t eventId) if(unclampedLen == UINT64_MAX) unclampedLen = 0; if(unclampedLen == 0) - unclampedLen = m_IsBuffer ? m_Ctx.GetBuffer(m_BufferID)->length : 0; + { + uint64_t bufLen = m_IsBuffer ? m_Ctx.GetBuffer(m_BufferID)->length : 0; + uint64_t bufOffs = CurrentByteOffset(); - uint64_t clampedLen = - qMin(unclampedLen - CurrentByteOffset(), uint64_t(buf->stride * (MaxVisibleRows + 2))); + if(bufOffs >= bufLen) + unclampedLen = 0; + else + unclampedLen = bufLen - bufOffs; + } + + uint64_t clampedLen = qMin(unclampedLen, uint64_t(buf->stride * (MaxVisibleRows + 2))); if(m_IsBuffer) {