Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Commit

Permalink
Fix crash when pasting large selections near the rightmost channel (#137
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nyanpasu64 authored May 8, 2019
1 parent 625589f commit dfea2f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
5 changes: 4 additions & 1 deletion Source/PatternAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ std::optional<CSelection> 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;
Expand Down
3 changes: 2 additions & 1 deletion Source/PatternEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ class CPatternEditor {
static const int ROW_HEIGHT;

// Variables
private:
public:
CFamiTrackerDoc *m_pDocument;
private:
CFamiTrackerView *m_pView;

// GDI objects
Expand Down
30 changes: 9 additions & 21 deletions Source/PatternEditorTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "stdafx.h"
#include "PatternEditorTypes.h"
#include "FamiTrackerDoc.h"
#include <utility>

// CCursorPos /////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
*/
1 change: 1 addition & 0 deletions Source/PatternEditorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; // // //
Expand Down

0 comments on commit dfea2f5

Please sign in to comment.