mirror of https://github.com/KDE/kasts.git
Fix and prevent nullptr dereferences in AudioManager
This would happen when the current track is changed to "no track". Signals from the backend KMediaSession would still trigger duration() calls which would try to dereference the pointer to the current track entry.
This commit is contained in:
parent
95590dd4e5
commit
8ddb278e8a
|
@ -390,9 +390,14 @@ void AudioManager::play()
|
||||||
if (isStreaming()) {
|
if (isStreaming()) {
|
||||||
if (!NetworkConnectionManager::instance().streamingAllowed()) {
|
if (!NetworkConnectionManager::instance().streamingAllowed()) {
|
||||||
qCDebug(kastsAudio) << "Refusing to play: no connection or streaming on metered connection not allowed";
|
qCDebug(kastsAudio) << "Refusing to play: no connection or streaming on metered connection not allowed";
|
||||||
|
QString feedUrl, entryId;
|
||||||
|
if (d->m_entry) {
|
||||||
|
feedUrl = d->m_entry->feed()->url();
|
||||||
|
entryId = d->m_entry->id();
|
||||||
|
}
|
||||||
Q_EMIT logError(Error::Type::MeteredStreamingNotAllowed,
|
Q_EMIT logError(Error::Type::MeteredStreamingNotAllowed,
|
||||||
d->m_entry->feed()->url(),
|
feedUrl,
|
||||||
d->m_entry->id(),
|
entryId,
|
||||||
0,
|
0,
|
||||||
i18n("No connection or streaming on metered connection not allowed"),
|
i18n("No connection or streaming on metered connection not allowed"),
|
||||||
QString());
|
QString());
|
||||||
|
@ -484,7 +489,7 @@ bool AudioManager::canGoNext() const
|
||||||
// check if there is a next track
|
// check if there is a next track
|
||||||
if (index < DataManager::instance().queue().count() - 1) {
|
if (index < DataManager::instance().queue().count() - 1) {
|
||||||
Entry *next_entry = DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]);
|
Entry *next_entry = DataManager::instance().getEntry(DataManager::instance().queue()[index + 1]);
|
||||||
if (next_entry->enclosure()) {
|
if (next_entry && next_entry->enclosure()) {
|
||||||
qCDebug(kastsAudio) << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
|
qCDebug(kastsAudio) << "Enclosure status" << next_entry->enclosure()->path() << next_entry->enclosure()->status();
|
||||||
if (next_entry->enclosure()->status() == Enclosure::Downloaded) {
|
if (next_entry->enclosure()->status() == Enclosure::Downloaded) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -543,9 +548,12 @@ void AudioManager::playerDurationChanged(qint64 duration)
|
||||||
qCDebug(kastsAudio) << "AudioManager::playerDurationChanged" << duration;
|
qCDebug(kastsAudio) << "AudioManager::playerDurationChanged" << duration;
|
||||||
|
|
||||||
// Check if duration mentioned in enclosure corresponds to real duration
|
// Check if duration mentioned in enclosure corresponds to real duration
|
||||||
if (duration > 0 && (duration / 1000) != d->m_entry->enclosure()->duration()) {
|
if (d->m_entry && d->m_entry->enclosure()) {
|
||||||
qCDebug(kastsAudio) << "Correcting duration of" << d->m_entry->id() << "to" << duration / 1000 << "(was" << d->m_entry->enclosure()->duration() << ")";
|
if (duration > 0 && (duration / 1000) != d->m_entry->enclosure()->duration()) {
|
||||||
d->m_entry->enclosure()->setDuration(duration / 1000);
|
qCDebug(kastsAudio) << "Correcting duration of" << d->m_entry->id() << "to" << duration / 1000 << "(was" << d->m_entry->enclosure()->duration()
|
||||||
|
<< ")";
|
||||||
|
d->m_entry->enclosure()->setDuration(duration / 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 correctedDuration = duration;
|
qint64 correctedDuration = duration;
|
||||||
|
@ -580,7 +588,7 @@ void AudioManager::savePlayPosition()
|
||||||
checkForPendingSeek();
|
checkForPendingSeek();
|
||||||
|
|
||||||
if (!d->m_lockPositionSaving) {
|
if (!d->m_lockPositionSaving) {
|
||||||
if (d->m_entry) {
|
if (d->m_entry && d->m_entry->enclosure()) {
|
||||||
if (d->m_entry->enclosure()) {
|
if (d->m_entry->enclosure()) {
|
||||||
d->m_entry->enclosure()->setPlayPosition(position());
|
d->m_entry->enclosure()->setPlayPosition(position());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue