Skip to content

Commit

Permalink
Merge pull request #4107 from uklotzde/lp1936396-autodj-crash
Browse files Browse the repository at this point in the history
lp1936396 AutoDJCratesDAO: Fix crash after loading/unloading tracks
  • Loading branch information
ywwg authored Jul 18, 2021
2 parents c29d9f6 + 156eb90 commit 782561c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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

0 comments on commit 782561c

Please sign in to comment.