From 1611e8dd6101e6f007d39635ff7de98c4bbe6418 Mon Sep 17 00:00:00 2001 From: Francisco Zurita Date: Mon, 11 Apr 2016 09:31:44 -0400 Subject: [PATCH] fix zelda subscreen crash --- src/FrameBuffer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp index 53d39448..bbb5a30c 100644 --- a/src/FrameBuffer.cpp +++ b/src/FrameBuffer.cpp @@ -542,10 +542,15 @@ void FrameBufferList::saveBuffer(u32 _address, u16 _format, u16 _size, u16 _widt m_prevColorImageHeight = gDP.colorImage.height; else if (gDP.colorImage.height == 0) gDP.colorImage.height = m_prevColorImageHeight; + gDP.colorImage.height = min(gDP.colorImage.height, VI.height); - m_pCurrent->m_endAddress = min(RDRAMSize, m_pCurrent->m_startAddress + (((m_pCurrent->m_width * gDP.colorImage.height) << m_pCurrent->m_size >> 1) - 1)); - } else if (m_pCurrent->m_needHeightCorrection && gDP.colorImage.height != 0) { - m_pCurrent->m_endAddress = min(RDRAMSize, m_pCurrent->m_startAddress + (((m_pCurrent->m_width * gDP.colorImage.height) << m_pCurrent->m_size >> 1) - 1)); + } + + //Non-auxiliary buffers are always corrected, auxiliary buffers are correct only if they need correction. + //Also, before making any adjustments, make sure gDP.colorImage.height has a valid value. + if((!m_pCurrent->isAuxiliary() || m_pCurrent->m_needHeightCorrection) && gDP.colorImage.height != 0) + { + m_pCurrent->m_endAddress = min(RDRAMSize, m_pCurrent->m_startAddress + (((m_pCurrent->m_width * gDP.colorImage.height) << m_pCurrent->m_size >> 1) - 1)); } if (!m_pCurrent->_isMarioTennisScoreboard() && !m_pCurrent->m_isDepthBuffer && !m_pCurrent->m_copiedToRdram && !m_pCurrent->m_cfb && !m_pCurrent->m_cleared && m_pCurrent->m_RdramCopy.empty() && gDP.colorImage.height > 1) {