MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other) leaves dangling noteOffObject pointers


#1

I have a function which returns a MidiMessageSequence. sequenceA is the variable local to the function. It gets assigned to sequenceB in the calling function. The MidiMessageSequence has two MidiMessages, a note on and a note off.

From the XCode debugger:


//========================================================================================
(lldb) p sequenceA.list
(juce::OwnedArray<juce::MidiMessageSequence::MidiEventHolder, juce::DummyCriticalSection>) $70 = {
  data = {
    elements = {
      data = 0x00006000004723c0
    }
    numAllocated = 8
  }
  numUsed = 2
  leakDetector896 = {}
}
(lldb) p sequenceA.list[0]
(juce::MidiMessageSequence::MidiEventHolder *) $71 = 0x000060000045bd20
(lldb) p sequenceA.list[1]
(juce::MidiMessageSequence::MidiEventHolder *) $72 = 0x000060000045cd70
(lldb) p sequenceA.list[0]->noteOffObject
(juce::MidiMessageSequence::MidiEventHolder *) $73 = 0x000060000045cd70
//========================================================================================
(lldb) p sequenceB.list
(juce::OwnedArray<juce::MidiMessageSequence::MidiEventHolder, juce::DummyCriticalSection>) $74 = {
  data = {
    elements = {
      data = 0x0000608000271e80
    }
    numAllocated = 8
  }
  numUsed = 2
  leakDetector896 = {}
}
(lldb) p sequenceB.list[0]
(juce::MidiMessageSequence::MidiEventHolder *) $75 = 0x0000608000454730
(lldb) p sequenceB.list[1]
(juce::MidiMessageSequence::MidiEventHolder *) $76 = 0x0000608000446090
(lldb) p sequenceB.list[0]->noteOffObject
(juce::MidiMessageSequence::MidiEventHolder *) $77 = 0x000060000045cd70
(lldb) 

In the first sequence you can see there are two messages in the list and the first event points to the second event.

In the second sequence you can see the two events in the list different points, but the noteOffObject is still pointing to the object in the first sequence that no longer exists.

The following seems to fix it, but I'm not sure if it's the best way to do it.

MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
​{
    list.addCopiesOf (other.list);
    updateMatchedPairs();
}

R


#2

Ah, thanks for the heads-up, I'll investigate..