diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 67046ecf91..1ce0d1191e 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -8,6 +8,7 @@ #include #include +#include "Common/MathUtil.h" #include "Common/Timer.h" #include "Core/ConfigManager.h" @@ -419,11 +420,11 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16) { // if Z is in 16 bit format you must return a 16 bit integer - ret = ((u32)(val * 65536.0f)); + ret = MathUtil::Clamp((u32)(val * 65536.0f), 0, 0xFFFF); } else { - ret = ((u32)(val * 16777216.0f)); + ret = MathUtil::Clamp((u32)(val * 16777216.0f), 0, 0xFFFFFF); } D3D::context->Unmap(read_tex, 0); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 638192df44..50a166e2da 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -12,6 +12,7 @@ #include "Common/Atomic.h" #include "Common/CommonPaths.h" #include "Common/FileUtil.h" +#include "Common/MathUtil.h" #include "Common/StringUtil.h" #include "Common/Thread.h" #include "Common/Timer.h" @@ -940,7 +941,7 @@ void Renderer::UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRec if (type == PEEK_Z) { float* ptr = (float*)data; - value = (u32)(ptr[yData * targetPixelRcWidth + xData] * 16777216.0f); + value = MathUtil::Clamp((u32)(ptr[yData * targetPixelRcWidth + xData] * 16777216.0f), 0, 0xFFFFFF); } else {