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

lp1936396 AutoDJCratesDAO: Fix crash after loading/unloading tracks #4107

Merged
merged 1 commit into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions src/library/dao/autodjcratesdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,24 +1072,25 @@ void AutoDJCratesDAO::slotPlaylistTrackRemoved(int playlistId,

void AutoDJCratesDAO::slotPlayerInfoTrackChanged(
const QString& group, TrackPointer pNewTrack, TrackPointer pOldTrack) {
playerInfoTrackUnloaded(group, pOldTrack);
playerInfoTrackLoaded(group, pNewTrack);
if (pOldTrack) {
playerInfoTrackUnloaded(group, pOldTrack->getId());
}
if (pNewTrack) {
playerInfoTrackLoaded(group, pNewTrack->getId());
}
}

// Signaled by the PlayerInfo singleton when a track is loaded to a deck.
void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& a_strGroup,
TrackPointer a_pTrack) {
// This gets called with a null track during an unload. Filter that out.
if (a_pTrack == nullptr) {
void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& group,
TrackId trackId) {
VERIFY_OR_DEBUG_ASSERT(trackId.isValid()) {
return;
}

// This counts as an auto-DJ reference. The idea is to prevent tracks that
// are loaded into a deck from being randomly chosen.
TrackId trackId(a_pTrack->getId());
unsigned int numDecks = PlayerManager::numDecks();
for (unsigned int i = 0; i < numDecks; ++i) {
if (a_strGroup == PlayerManager::groupForDeck(i)) {
if (group == PlayerManager::groupForDeck(i)) {
// Update the number of auto-DJ-playlist references to this track.
QSqlQuery oQuery(m_database);
// UPDATE temp_autodj_crates SET autodjrefs = autodjrefs + 1
Expand All @@ -1109,10 +1110,12 @@ void AutoDJCratesDAO::playerInfoTrackLoaded(const QString& a_strGroup,

// Signaled by the PlayerInfo singleton when a track is unloaded from a deck.
void AutoDJCratesDAO::playerInfoTrackUnloaded(const QString& group,
TrackPointer pTrack) {
TrackId trackId) {
VERIFY_OR_DEBUG_ASSERT(trackId.isValid()) {
return;
}
// This counts as an auto-DJ reference. The idea is to prevent tracks that
// are loaded into a deck from being randomly chosen.
TrackId trackId(pTrack->getId());
unsigned int numDecks = PlayerManager::numDecks();
for (unsigned int i = 0; i < numDecks; ++i) {
if (group == PlayerManager::groupForDeck(i)) {
Expand Down
4 changes: 2 additions & 2 deletions src/library/dao/autodjcratesdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class AutoDJCratesDAO : public QObject {
TrackPointer pOldTrack);

private:
void playerInfoTrackLoaded(const QString& group, TrackPointer pTrack);
void playerInfoTrackUnloaded(const QString& group, TrackPointer pTrack);
void playerInfoTrackLoaded(const QString& group, TrackId trackId);
void playerInfoTrackUnloaded(const QString& group, TrackId trackId);
void updateAutoDjCrate(CrateId crateId);
void deleteAutoDjCrate(CrateId crateId);

Expand Down