Skip to content

Commit

Permalink
[Fix] Instrument tab: Crash when trying to remove the only point of a…
Browse files Browse the repository at this point in the history
…n envelope.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22859 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jan 27, 2025
1 parent 04e5d16 commit 84e1b84
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions mptrack/View_ins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,15 @@ void CViewInstrument::OnDraw(CDC *pDC)
m_dcMemMain.MoveTo(x2, y2 - nspace);
m_dcMemMain.LineTo(x2, y2 + nspace);
}
uint32 maxpoint = EnvGetNumPoints();
uint32 numPoints = EnvGetNumPoints();
// Drawing Envelope
if(maxpoint)
if(numPoints)
{
maxpoint--;
m_dcMemMain.SelectObject(GetStockObject(DC_PEN));
m_dcMemMain.SetDCPenColor(TrackerSettings::Instance().rgbCustomColors[MODCOLOR_ENVELOPES]);
uint32 releaseNode = EnvGetReleaseNode();
RECT rect;
for(uint32 i = 0; i <= maxpoint; i++)
for(uint32 i = 0; i < numPoints; i++)
{
int x = PointToScreen(i);
int y = ValueToScreen(EnvGetValue(i));
Expand Down Expand Up @@ -1080,18 +1079,27 @@ bool CViewInstrument::EnvRemovePoint(uint32 nPoint)

PrepareUndo("Remove Envelope Point");
envelope->erase(envelope->begin() + nPoint);
if (nPoint >= envelope->size()) nPoint = envelope->size() - 1;
if (envelope->nLoopStart > nPoint) envelope->nLoopStart--;
if (envelope->nLoopEnd > nPoint) envelope->nLoopEnd--;
if (envelope->nSustainStart > nPoint) envelope->nSustainStart--;
if (envelope->nSustainEnd > nPoint) envelope->nSustainEnd--;
if (envelope->nReleaseNode>nPoint && envelope->nReleaseNode != ENV_RELEASE_NODE_UNSET) envelope->nReleaseNode--;
envelope->at(0).tick = 0;
if(nPoint >= envelope->size())
nPoint = envelope->size() - 1;
if(envelope->nLoopStart > nPoint)
envelope->nLoopStart--;
if(envelope->nLoopEnd > nPoint)
envelope->nLoopEnd--;
if(envelope->nSustainStart > nPoint)
envelope->nSustainStart--;
if(envelope->nSustainEnd > nPoint)
envelope->nSustainEnd--;
if(envelope->nReleaseNode > nPoint && envelope->nReleaseNode != ENV_RELEASE_NODE_UNSET)
envelope->nReleaseNode--;

if(envelope->size() <= 1)
{
// if only one node is left, just disable the envelope completely
*envelope = InstrumentEnvelope();
// If only one node is left, just disable the envelope completely
mpt::reset(*envelope);
} else
{
// If we removed the first node, make sure that we have a node on tick 0 again
envelope->at(0).tick = 0;
}

SetModified(InstrumentHint().Envelope(), true);
Expand Down

0 comments on commit 84e1b84

Please sign in to comment.