Add comments about nullptr guard

Add some comments which describe why we need to guard agains nullptr.
This commit is contained in:
Michael Gregorius
2023-09-16 19:19:37 +02:00
parent 73f9f36c9a
commit 6c3ae30c89

View File

@@ -570,6 +570,10 @@ f_cnt_t InstrumentTrack::beatLen( NotePlayHandle * _n ) const
void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
{
// Note: under certain circumstances the working buffer is a nullptr.
// These cases are triggered in PlayHandle::doProcessing when the play method is called with a nullptr.
// TODO: Find out if we can skip processing at a higher level if the buffer is nullptr.
// arpeggio- and chord-widget has to do its work -> adding sub-notes
// for chords/arpeggios
m_noteStacking.processNote( n );
@@ -580,6 +584,8 @@ void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
// all is done, so now lets play the note!
m_instrument->playNote( n, workingBuffer );
// Calling processAudioBuffer with a nullptr leads to crashes when checking if the buffer represents silence.
// Therefore we must guard against a nullptr here.
if (workingBuffer != nullptr)
{
const fpp_t frames = n->framesLeftForCurrentPeriod();