From 86f772ad38b5ff3432eb0b337d18936aaba5a6b0 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Tue, 14 Jun 2022 17:13:06 +0100 Subject: [PATCH] GS: Avoid Div by 0 on WriteImage --- pcsx2/GS/GSLocalMemory.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pcsx2/GS/GSLocalMemory.cpp b/pcsx2/GS/GSLocalMemory.cpp index 6e7f752099..17c5776c4e 100644 --- a/pcsx2/GS/GSLocalMemory.cpp +++ b/pcsx2/GS/GSLocalMemory.cpp @@ -832,7 +832,8 @@ void GSLocalMemory::WriteImage(int& tx, int& ty, const u8* src, int len, GIFRegB int la = (l + (bsx - 1)) & ~(bsx - 1); int ra = r & ~(bsx - 1); - int srcpitch = (r - l) * trbpp >> 3; + // Round up to the nearest byte (NFL 2K5 does r = 1, l = 0 bpp =4, causing divide by zero) + int srcpitch = (((r - l) * trbpp) + 7) >> 3; int h = len / srcpitch; if (ra - la >= bsx && h > 0) // "transfer width" >= "block width" && there is at least one full row