LMMS / LMMS/lmms

Rare crash on replacing instruments while playing notes

Open
#6,630 7 comments 0 reactions 1 assignee Claimed by @sakertooth View on GitHub
bug
Dominant language
C++
Stars
10.4k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
7

Description

### 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](https://github.com/LMMS/lmms/files/10593792/a_lot_of_notes.mmp.zip)

Since it's very hard to reproduce, you may want to modify the code like this:
```diff
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.