From c233aa121b59559bd29b675d2047efaf741e8879 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 25 Dec 2011 16:49:22 +0000 Subject: invalid pointer fixes --- muse2/muse/midiedit/dcanvas.cpp | 2 +- muse2/muse/midiedit/dlist.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index bdf16b6e..4c033946 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -1605,7 +1605,7 @@ void DrumCanvas::rebuildOurDrumMap() if (instrument_map!=old_instrument_map) { - if (debugMsg) printf("rebuilt drummap and instrument map, size is now %i\n",size); + if (debugMsg) printf("rebuilt drummap and instrument map, size is now %i\n",size); songChanged(SC_EVENT_INSERTED); // force an update of the itemlist emit ourDrumMapChanged(true); diff --git a/muse2/muse/midiedit/dlist.cpp b/muse2/muse/midiedit/dlist.cpp index bcdbad79..2cbaceda 100644 --- a/muse2/muse/midiedit/dlist.cpp +++ b/muse2/muse/midiedit/dlist.cpp @@ -299,11 +299,12 @@ void DList::viewMousePressEvent(QMouseEvent* ev) int instrument = y / TH; if (instrument >= ourDrumMapSize) instrument=ourDrumMapSize-1; if (instrument < 0) instrument=0; - MusECore::DrumMap* dm = &ourDrumMap[instrument]; - MusECore::DrumMap dm_old = *dm; setCurDrumInstrument(instrument); + MusECore::DrumMap* dm = &ourDrumMap[instrument]; + MusECore::DrumMap dm_old = *dm; + startY = y; sInstrument = instrument; drag = START_DRAG; @@ -724,7 +725,8 @@ void DList::setCurDrumInstrument(int instr) if (currentlySelected != dm) { currentlySelected = dm; emit curDrumInstrumentChanged(instr); - MusEGlobal::song->update(SC_DRUMMAP); + //MusEGlobal::song->update(SC_DRUMMAP); //FINDMICHJETZT what for?? wtf? + redraw(); // FINDMICHJETZT using redraw() instead of the above. } } @@ -1084,12 +1086,33 @@ int DList::getSelectedInstrument() void DList::ourDrumMapChanged(bool instrMapChanged) { int selIdx = currentlySelected - ourDrumMap; + int editIdx = editEntry ? (editEntry - ourDrumMap) : -1; ourDrumMap=dcanvas->getOurDrumMap(); ourDrumMapSize=dcanvas->getOurDrumMapSize(); if (instrMapChanged) - editEntry=NULL; + { + if (editEntry!=NULL) + { + printf("THIS SHOULD NEVER HAPPEN: DList::ourDrumMapChanged(true) caused editEntry to be\n" + " invalidated. The current active editor will have no\n" + " effect, expect potential breakage...\n"); + editEntry=NULL; + } + } + else // that is: if (!instrMapChanged) + { + // if the instrumentMap has not changed, then its size and so + // ourDrumMapSize cannot have changed as well. + if (editIdx >= ourDrumMapSize) + { + printf("THIS SHOULD NEVER HAPPEN: editIdx got out of bounds although ourDrumMapSize\n" + " cannot have changed (actually)\n"); + editIdx=-1; + } + editEntry=(editIdx>=0) ? &ourDrumMap[editIdx] : NULL; + } if (selIdx >= ourDrumMapSize) selIdx=ourDrumMapSize-1; if (selIdx < 0) selIdx=0; -- cgit v1.2.3