From dfea2f598c94b66bfffc4002832e842653a822b9 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Wed, 8 May 2019 02:02:36 -0700 Subject: [PATCH] Fix crash when pasting large selections near the rightmost channel (#137) --- Source/PatternAction.cpp | 5 ++++- Source/PatternEditor.h | 3 ++- Source/PatternEditorTypes.cpp | 30 +++++++++--------------------- Source/PatternEditorTypes.h | 1 + 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Source/PatternAction.cpp b/Source/PatternAction.cpp index b46f8394..07457237 100644 --- a/Source/PatternAction.cpp +++ b/Source/PatternAction.cpp @@ -182,7 +182,10 @@ std::optional CPatternAction::SetTargetSelection(CPatternEditor *pPa End.m_iColumn = C_EFF4_PARAM2; } } - + + Start.fixInvalid(*pPatternEditor->m_pDocument); + End.fixInvalid(*pPatternEditor->m_pDocument); + // Construct selection. CSelection newSelection; newSelection.m_cpStart = Start; diff --git a/Source/PatternEditor.h b/Source/PatternEditor.h index 0d3f418b..d7b8975e 100644 --- a/Source/PatternEditor.h +++ b/Source/PatternEditor.h @@ -294,8 +294,9 @@ class CPatternEditor { static const int ROW_HEIGHT; // Variables -private: +public: CFamiTrackerDoc *m_pDocument; +private: CFamiTrackerView *m_pView; // GDI objects diff --git a/Source/PatternEditorTypes.cpp b/Source/PatternEditorTypes.cpp index 59752f84..749cb489 100644 --- a/Source/PatternEditorTypes.cpp +++ b/Source/PatternEditorTypes.cpp @@ -23,6 +23,7 @@ #include "stdafx.h" #include "PatternEditorTypes.h" #include "FamiTrackerDoc.h" +#include // CCursorPos ///////////////////////////////////////////////////////////////////// @@ -77,6 +78,14 @@ bool CCursorPos::IsValid(int RowCount, int ChannelCount) const // // // return true; } +void CCursorPos::fixInvalid(CFamiTrackerDoc const & document) { + auto channel_count = document.GetChannelCount(); + if (this->m_iChannel >= channel_count) { + this->m_iChannel = channel_count; + this->m_iColumn = C_EFF4_PARAM2; + } +} + // CSelection ///////////////////////////////////////////////////////////////////// int CSelection::GetRowStart() const @@ -392,25 +401,4 @@ void CPatternIterator::Warp() } while (m_iRow < 0) m_iRow += m_pDocument->GetCurrentPatternLength(m_iTrack, --m_iFrame); - //m_iFrame %= m_pDocument->GetFrameCount(m_iTrack); - //if (m_iFrame < 0) m_iFrame += m_pDocument->GetFrameCount(m_iTrack); -} - -// CPatternEditorLayout //////////////////////////////////////////////////////// -/* -CPatternEditorLayout::CPatternEditorLayout() -{ } - -void CPatternEditorLayout::SetSize(int Width, int Height) -{ -// m_iWinWidth = width; -// m_iWinHeight = height - ::GetSystemMetrics(SM_CYHSCROLL); -} - -void CPatternEditorLayout::CalculateLayout() -{ - // Calculate pattern layout. Must be called when layout or window size has changed - -} -*/ diff --git a/Source/PatternEditorTypes.h b/Source/PatternEditorTypes.h index bd94eb82..fcca7bdb 100644 --- a/Source/PatternEditorTypes.h +++ b/Source/PatternEditorTypes.h @@ -188,6 +188,7 @@ class CCursorPos { bool operator <(const CCursorPos &other) const; bool operator <=(const CCursorPos &other) const; bool IsValid(int RowCount, int ChannelCount) const; // // // + void fixInvalid(CFamiTrackerDoc const & document); public: int m_iFrame; // // //