From 3a4defe210fc5d826c27f668f36fe8f2e8aa4f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 26 Sep 2024 00:41:01 +0200 Subject: [PATCH] DrawEngineCommon: Enforce the limit on vertex decoding Should help #18894 which draws using a nonsense index buffer sometimes, causing problems since we decode the whole range... --- GPU/Common/DrawEngineCommon.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index b517850ee37b..f61c4cb70eb0 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -971,7 +971,6 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti void DrawEngineCommon::DecodeVerts(u8 *dest) { // Note that this should be able to continue a partial decode - we don't necessarily start from zero here (although we do most of the time). - int i = decodeVertsCounter_; int stride = (int)dec_->GetDecVtxFmt().stride; for (; i < numDrawVerts_; i++) { @@ -981,6 +980,12 @@ void DrawEngineCommon::DecodeVerts(u8 *dest) { drawVertexOffsets_[i] = numDecodedVerts_ - indexLowerBound; int indexUpperBound = dv.indexUpperBound; + + if (indexUpperBound + 1 - indexLowerBound + numDecodedVerts_ >= VERTEX_BUFFER_MAX) { + // Hit our limit! Stop decoding in this draw. + break; + } + // Decode the verts (and at the same time apply morphing/skinning). Simple. dec_->DecodeVerts(dest + numDecodedVerts_ * stride, dv.verts, &dv.uvScale, indexLowerBound, indexUpperBound); numDecodedVerts_ += indexUpperBound - indexLowerBound + 1;