From 1915a0ea6dc5f68c41e2d0e774ba7ec939e30f09 Mon Sep 17 00:00:00 2001 From: shaun <962914132@qq.com> Date: Thu, 11 Dec 2025 10:40:59 +0100 Subject: [PATCH] Fix: Disable SSE2 (which causes crash) while using DXGI --- client/ScreenCapture.h | 43 +++++++++++++++++++++++++++++++++++++ client/ScreenCapturerDXGI.h | 4 ++++ client/ghost_vs2015.vcxproj | 1 + 3 files changed, 48 insertions(+) diff --git a/client/ScreenCapture.h b/client/ScreenCapture.h index 9d97149..19874fb 100644 --- a/client/ScreenCapture.h +++ b/client/ScreenCapture.h @@ -239,10 +239,53 @@ public: } public: + virtual BOOL UsingDXGI() const { + return FALSE; + } + //*************************************** 图像差异算法(串行) ************************************* + ULONG CompareBitmapDXGI(LPBYTE CompareSourData, LPBYTE CompareDestData, LPBYTE szBuffer, + DWORD ulCompareLength, BYTE algo, int startPostion = 0) + { + // Windows规定一个扫描行所占的字节数必须是4的倍数, 所以用DWORD比较 + LPDWORD p1 = (LPDWORD)CompareDestData, p2 = (LPDWORD)CompareSourData; + LPBYTE p = szBuffer; + ULONG channel = algo == ALGORITHM_GRAY ? 1 : 4; + ULONG ratio = algo == ALGORITHM_GRAY ? 4 : 1; + for (ULONG i = 0; i < ulCompareLength; i += 4, ++p1, ++p2) { + if (*p1 == *p2) + continue; + ULONG index = i; + LPDWORD pos1 = p1++, pos2 = p2++; + // 计算有几个像素值不同 + for (i += 4; i < ulCompareLength && *p1 != *p2; i += 4, ++p1, ++p2); + ULONG ulCount = i - index; + memcpy(pos1, pos2, ulCount); // 更新目标像素 + + *(LPDWORD)(p) = index + startPostion; + *(LPDWORD)(p + sizeof(ULONG)) = ulCount / ratio; + p += 2 * sizeof(ULONG); + if (channel != 1) { + memcpy(p, pos2, ulCount); + p += ulCount; + } + else { + for (LPBYTE end = p + ulCount / ratio; p < end; p += channel, ++pos2) { + LPBYTE src = (LPBYTE)pos2; + *p = (306 * src[2] + 601 * src[0] + 117 * src[1]) >> 10; + } + } + } + + return p - szBuffer; + } + //*************************************** 图像差异算法 SSE2 优化版 ************************************* virtual ULONG CompareBitmap(LPBYTE CompareSourData, LPBYTE CompareDestData, LPBYTE szBuffer, DWORD ulCompareLength, BYTE algo, int startPostion = 0) { + if (UsingDXGI()) + return CompareBitmapDXGI(CompareSourData, CompareDestData, szBuffer, ulCompareLength, algo, startPostion); + LPBYTE p = szBuffer; ULONG channel = algo == ALGORITHM_GRAY ? 1 : 4; ULONG ratio = algo == ALGORITHM_GRAY ? 4 : 1; diff --git a/client/ScreenCapturerDXGI.h b/client/ScreenCapturerDXGI.h index 1cd57db..15ae039 100644 --- a/client/ScreenCapturerDXGI.h +++ b/client/ScreenCapturerDXGI.h @@ -40,6 +40,10 @@ public: SAFE_DELETE_ARRAY(m_RectBuffer); } + virtual BOOL UsingDXGI() const { + return TRUE; + } + void InitDXGI(BOOL all) { m_iScreenX = 0; diff --git a/client/ghost_vs2015.vcxproj b/client/ghost_vs2015.vcxproj index 1c76e3c..4efdc0d 100644 --- a/client/ghost_vs2015.vcxproj +++ b/client/ghost_vs2015.vcxproj @@ -246,6 +246,7 @@ +