Skip to content

Rare crash on replacing instruments while playing notes #6630

Open
@PhysSong

Description

@PhysSong

Summary

LMMS may crash on replacing instruments while playing notes. This also happens when loading preset to an instrument track while it's playing.

Steps to reproduce

  1. Open and the provided project file(alternatively, you can open any instrument and put a lot of notes there)
  2. Try replacing instruments until it crash

a_lot_of_notes.mmp.zip

Since it's very hard to reproduce, you may want to modify the code like this:

diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp
index 0e75c990a..942081917 100644
--- a/src/tracks/InstrumentTrack.cpp
+++ b/src/tracks/InstrumentTrack.cpp
@@ -1027,9 +1027,11 @@ Instrument * InstrumentTrack::loadInstrument(const QString & _plugin_name,
 		Q_ASSERT(!key);
 
 	silenceAllNotes( true );
+	QThread::msleep(100);
 
 	lock();
 	delete m_instrument;
+	QThread::msleep(100);
 	m_instrument = Instrument::instantiate(_plugin_name, this,
 					key, keyFromDnd);
 	unlock();

Technical details

In InstrumentTrack::loadInstrument, m_instrument may be used while being deleted. Also, lock()ing after calling silenceAllNotes() doesn't prevent new notes to be added in between those two calls.
When a NotePlayHandle is added between two calls, it may try to use its m_instrumentTrack->instrument() during their deletion(or after deletion) since the returned value itself is not null.
In my cases, the crash always happened in InstrumentSoundShaping::releaseFrames , at the line calling m_instrumentTrack->instrument()->desiredReleaseFrames().

The same thing may happen in InstrumentTrack::loadTrackSpecificSettings, too.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions