From d3ebd4b318c7219f111fc35840035e0ca4155dac Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 26 Jul 2016 18:24:01 +0530 Subject: [PATCH] GSDX-TextureCache: Add proper rounding when unscaling texture size Fixes flickering issues on Dragon Ball Z Budokai Tenkaichi FMV's on custom resolution, might also help prevent some crashes on custom resolution. --- plugins/GSdx/GSTextureCache.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 0017799a14..4bd85d360b 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -1738,8 +1738,11 @@ void GSTextureCache::Target::Update() GSVector2i t_size = m_texture->GetSize(); GSVector2 t_scale = m_texture->GetScale(); - t_size.x = (int)((float)t_size.x/max(1.0f, t_scale.x)); - t_size.y = (int)((float)t_size.y/max(1.0f, t_scale.y)); + + //Avoids division by zero when calculating texture size. + t_scale = GSVector2(max(1.0f, t_scale.x), max(1.0f, t_scale.y)); + t_size.x = lround(static_cast(t_size.x) / t_scale.x); + t_size.y = lround(static_cast(t_size.y) / t_scale.y); // Don't load above the GS memory int max_y_blocks = (MAX_BLOCKS - m_TEX0.TBP0) / max(1u, m_TEX0.TBW);