Skip to content

Commit

Permalink
Fix crash with empty track
Browse files Browse the repository at this point in the history
When a track hasn't loaded a file the `m_transportSource` won't contain
a source and thus crashes on some interactions (but not on others).
Protect the calls by first checking whether an audio file was loaded.

Also call the *playing state changed* callback since the caller assumes
the change actually changed so it needs to be "reset" for the UI to
match the actual behavior.
  • Loading branch information
ServiusHack committed Sep 22, 2024
1 parent ad10dab commit ffc68ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Output channels can be activated and deactivated with one button click
* Show *about* dialog with version number.

### Fixed

* Fixed crash when playing, pausing or stopping a player with at least one empty track.

## [1.1.111] - 2022-10-12
28 changes: 21 additions & 7 deletions Source/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ float Track::getVolume() const

void Track::play()
{
setPosition(0);
m_transportSource.start();
startTimer(50);
m_playingStateChangedCallback(true);
if (m_currentAudioFileSource)
{
setPosition(0);
m_transportSource.start();
startTimer(50);
m_playingStateChangedCallback(true);
}
else
{
m_playingStateChangedCallback(false);
}
}

void Track::pause()
Expand All @@ -142,18 +149,25 @@ void Track::pause()
stopTimer();
m_playingStateChangedCallback(false);
}
else
else if (m_currentAudioFileSource)
{
m_transportSource.start();
startTimer(50);
m_playingStateChangedCallback(true);
}
else
{
m_playingStateChangedCallback(false);
}
}

void Track::stop()
{
m_transportSource.stop();
setPosition(0);
if (m_currentAudioFileSource)
{
m_transportSource.stop();
setPosition(0);
}
stopTimer();
m_playingStateChangedCallback(false);
}
Expand Down

0 comments on commit ffc68ad

Please sign in to comment.