From 9c258efa3ae3c49ed52cd8f41f6f58eb669257f2 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 13 Jan 2016 02:53:57 +0100 Subject: [PATCH] Workaround crash from SpotifyParser --- .../accounts/spotify/SpotifyAccount.cpp | 17 +++++++++++++++-- .../accounts/spotify/SpotifyAccount.h | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index 1306d4713b..91f562ab08 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -842,15 +842,28 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg const QString qid = msg.value( "qid" ).toString(); if ( m_qidToSlotMap.contains( qid ) ) { - QObject* receiver = m_qidToSlotMap[ qid ].first; + QPointer< QObject > receiver = m_qidToSlotMap[ qid ].first; QString slot = m_qidToSlotMap[ qid ].second; m_qidToSlotMap.remove( qid ); + QVariant extraData; if ( m_qidToExtraData.contains( qid ) ) extraData = m_qidToExtraData.take( qid ); - QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ), Q_ARG( QVariant, extraData ) ); + // FIXME: SpotifyParser is sometimes a dangling pointer, haven't found a real way to reproduce: happens sometimes when dropping a playlist url onto the sidebar + //Q_ASSERT( !receiver.isNull() ); + + if ( !receiver.isNull() ) + { + QMetaObject::invokeMethod( receiver, slot.toLatin1(), Q_ARG( QString, msgType ), Q_ARG( QVariantMap, msg ), Q_ARG( QVariant, extraData ) ); + } + else + { + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( + tr( "Spotify account could not finish action. Try again.n" ) + ) ); + } } else if ( msgType == "allPlaylists" ) { diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.h b/src/libtomahawk/accounts/spotify/SpotifyAccount.h index 10da048b97..c488e688e8 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.h @@ -172,7 +172,7 @@ private slots: QPointer m_spotifyResolver; QPointer< InfoSystem::SpotifyInfoPlugin > m_infoPlugin; - QMap > m_qidToSlotMap; + QMap, QString> > m_qidToSlotMap; QMap m_qidToExtraData; // List of synced spotify playlists in config UI