From 401216608573182b0ece84ceaa9d2cdfb60fe757 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 9 Mar 2017 23:39:48 +1000 Subject: [PATCH] VideoCommon: Fix crash at startup with virtual XFB enabled --- Source/Core/VideoCommon/FramebufferManagerBase.cpp | 10 ++++------ Source/Core/VideoCommon/FramebufferManagerBase.h | 4 ++-- Source/Core/VideoCommon/RenderBase.cpp | 10 +++++----- Source/Core/VideoCommon/RenderBase.h | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoCommon/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/FramebufferManagerBase.cpp index 0fc65a5443..dd2cc88735 100644 --- a/Source/Core/VideoCommon/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/FramebufferManagerBase.cpp @@ -248,20 +248,18 @@ void FramebufferManagerBase::ReplaceVirtualXFB() } } -int FramebufferManagerBase::ScaleToVirtualXfbWidth(int x) +int FramebufferManagerBase::ScaleToVirtualXfbWidth(int x, const TargetRectangle& target_rectangle) { if (g_ActiveConfig.RealXFBEnabled()) return x; - return x * static_cast(g_renderer->GetTargetRectangle().GetWidth()) / - static_cast(FramebufferManagerBase::LastXfbWidth()); + return x * target_rectangle.GetWidth() / s_last_xfb_width; } -int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y) +int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y, const TargetRectangle& target_rectangle) { if (g_ActiveConfig.RealXFBEnabled()) return y; - return y * static_cast(g_renderer->GetTargetRectangle().GetHeight()) / - static_cast(FramebufferManagerBase::LastXfbHeight()); + return y * target_rectangle.GetHeight() / s_last_xfb_height; } diff --git a/Source/Core/VideoCommon/FramebufferManagerBase.h b/Source/Core/VideoCommon/FramebufferManagerBase.h index 47426b2e01..c780a3fa21 100644 --- a/Source/Core/VideoCommon/FramebufferManagerBase.h +++ b/Source/Core/VideoCommon/FramebufferManagerBase.h @@ -57,8 +57,8 @@ public: static void SetLastXfbHeight(unsigned int height) { s_last_xfb_height = height; } static unsigned int LastXfbWidth() { return s_last_xfb_width; } static unsigned int LastXfbHeight() { return s_last_xfb_height; } - static int ScaleToVirtualXfbWidth(int x); - static int ScaleToVirtualXfbHeight(int y); + static int ScaleToVirtualXfbWidth(int x, const TargetRectangle& target_rectangle); + static int ScaleToVirtualXfbHeight(int y, const TargetRectangle& target_rectangle); static unsigned int GetEFBLayers() { return m_EFBLayers; } virtual std::pair GetTargetSize() const = 0; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 7e598e2373..a7d72d4929 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -84,8 +84,8 @@ Renderer::Renderer(int backbuffer_width, int backbuffer_height) FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); UpdateActiveConfig(); - CalculateTargetSize(); UpdateDrawRectangle(); + CalculateTargetSize(); OSDChoice = 0; OSDTime = 0; @@ -127,7 +127,7 @@ int Renderer::EFBToScaledX(int x) switch (g_ActiveConfig.iEFBScale) { case SCALE_AUTO: // fractional - return FramebufferManagerBase::ScaleToVirtualXfbWidth(x); + return FramebufferManagerBase::ScaleToVirtualXfbWidth(x, m_target_rectangle); default: return x * (int)m_efb_scale_numeratorX / (int)m_efb_scale_denominatorX; @@ -139,7 +139,7 @@ int Renderer::EFBToScaledY(int y) switch (g_ActiveConfig.iEFBScale) { case SCALE_AUTO: // fractional - return FramebufferManagerBase::ScaleToVirtualXfbHeight(y); + return FramebufferManagerBase::ScaleToVirtualXfbHeight(y, m_target_rectangle); default: return y * (int)m_efb_scale_numeratorY / (int)m_efb_scale_denominatorY; @@ -173,8 +173,8 @@ bool Renderer::CalculateTargetSize() { case SCALE_AUTO: case SCALE_AUTO_INTEGRAL: - newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH); - newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT); + newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH, m_target_rectangle); + newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT, m_target_rectangle); if (m_last_efb_scale == SCALE_AUTO_INTEGRAL) { diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 79c174e28c..d897e07307 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -168,7 +168,7 @@ protected: int m_backbuffer_width = 0; int m_backbuffer_height = 0; int m_last_efb_scale = 0; - TargetRectangle m_target_rectangle; + TargetRectangle m_target_rectangle = {}; bool m_xfb_written = false; FPSCounter m_fps_counter;