Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't process ejected tracks #11334

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,8 @@ void EngineBuffer::process(CSAMPLE* pOutput, const int iBufferSize) {
m_pScaleST->setSampleRate(m_sampleRate);
m_pScaleRB->setSampleRate(m_sampleRate);

bool bTrackLoading = m_iTrackLoading.loadAcquire() != 0;
if (!bTrackLoading && m_pause.tryLock()) {
bool hasStableTrack = m_pTrackLoaded->toBool() && m_iTrackLoading.loadAcquire() == 0;
if (hasStableTrack && m_pause.tryLock()) {
Comment on lines +1143 to +1144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might fix the issue, though my guess is that the problem stems from a memory access ordering issue. Have you tried refactoring m_iTrackLoading to a std::atomic<bool> and then use memory_order::seq_cst accesses everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue fortunately is pretty clear.
We have identified dff90d2
as the first failing commit.
I have introduced an extra engine callback where the track is already ejected. m_pTrackLoaded is false than.
This is required to clear the effect buffers.

Calling processTrackLocked() without a track is obviously wrong.
I have not found out where exactly the bad memory access happens. Valgrind reveals only the symptom inside Soundtouch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the CO is not subject to data-races?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because m_pTrackLoaded and m_iTrackLoading are atomic and only changed under the m_pause lock.

processTrackLocked(pOutput, iBufferSize, m_sampleRate);
// release the pauselock
m_pause.unlock();
Expand Down