From: <sag...@us...> - 2013-07-04 01:04:57
|
Revision: 2494 http://sourceforge.net/p/modplug/code/2494 Author: saga-games Date: 2013-07-04 01:04:48 +0000 (Thu, 04 Jul 2013) Log Message: ----------- [Fix] Pattern Editor: When removing channels or rows from a pattern, a crash could occour when the cursor was previously placed in a now inaccesible part of the pattern. Modified Paths: -------------- trunk/OpenMPT/mptrack/Draw_pat.cpp trunk/OpenMPT/mptrack/View_pat.cpp trunk/OpenMPT/mptrack/View_pat.h Modified: trunk/OpenMPT/mptrack/Draw_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/Draw_pat.cpp 2013-07-04 00:40:54 UTC (rev 2493) +++ trunk/OpenMPT/mptrack/Draw_pat.cpp 2013-07-04 01:04:48 UTC (rev 2494) @@ -1498,6 +1498,7 @@ rect.top += m_szHeader.cy; } InvalidateRect(&rect, FALSE); + SanitizeCursor(); } Modified: trunk/OpenMPT/mptrack/View_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_pat.cpp 2013-07-04 00:40:54 UTC (rev 2493) +++ trunk/OpenMPT/mptrack/View_pat.cpp 2013-07-04 01:04:48 UTC (rev 2494) @@ -3704,7 +3704,7 @@ //----------------------------------------------------------- { CSoundFile *pSndFile = GetSoundFile(); - if(pSndFile != nullptr && pSndFile->Patterns.IsValidPat(GetCurrentPattern())) + if(pSndFile != nullptr && pSndFile->Patterns.IsValidPat(GetCurrentPattern() && pSndFile->Patterns[GetCurrentPattern()].IsValidRow(cursor.GetRow()))) { return *pSndFile->Patterns[GetCurrentPattern()].GetpModCommand(cursor.GetRow(), cursor.GetChannel()); } @@ -3714,7 +3714,18 @@ } +// Sanitize cursor so that it can't point to an invalid position in the current pattern. +void CViewPattern::SanitizeCursor() +//--------------------------------- +{ + CSoundFile *pSndFile = GetSoundFile(); + if(pSndFile != nullptr && pSndFile->Patterns.IsValidPat(GetCurrentPattern())) + { + m_Cursor.Sanitize(GetSoundFile()->Patterns[m_nPattern].GetNumRows(), GetSoundFile()->Patterns[m_nPattern].GetNumChannels()); + } +}; + // Returns pointer to modcommand at given position. // If the position is not valid, a pointer to a dummy command is returned. ModCommand &CViewPattern::GetModCommand(CSoundFile &sndFile, const ModCommandPos &pos) Modified: trunk/OpenMPT/mptrack/View_pat.h =================================================================== --- trunk/OpenMPT/mptrack/View_pat.h 2013-07-04 00:40:54 UTC (rev 2493) +++ trunk/OpenMPT/mptrack/View_pat.h 2013-07-04 01:04:48 UTC (rev 2494) @@ -234,6 +234,7 @@ ORDERINDEX GetCurrentOrder() const { return static_cast<ORDERINDEX>(SendCtrlMessage(CTRLMSG_GETCURRENTORDER)); } // Get ModCommand at the pattern cursor position. ModCommand &GetCursorCommand() { return GetModCommand(m_Cursor); }; + void SanitizeCursor(); UINT GetColumnOffset(PatternCursor::Columns column) const; POINT GetPointFromPosition(PatternCursor cursor); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |