mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Don't crash on exit when unregistering cover providers
This commit is contained in:
parent
6e86caae2c
commit
2e9ec3e9d4
@ -27,7 +27,7 @@ CoverProviders::CoverProviders()
|
|||||||
void CoverProviders::AddProvider(CoverProvider* provider) {
|
void CoverProviders::AddProvider(CoverProvider* provider) {
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex_);
|
QMutexLocker locker(&mutex_);
|
||||||
cover_providers_.append(provider);
|
cover_providers_.insert(provider, provider->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
qLog(Debug) << "Registered cover provider" << provider->name();
|
qLog(Debug) << "Registered cover provider" << provider->name();
|
||||||
@ -39,11 +39,20 @@ void CoverProviders::RemoveProvider(CoverProvider* provider) {
|
|||||||
if (!provider)
|
if (!provider)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qLog(Debug) << "Unregistered cover provider" << provider->name();
|
// It's not safe to dereference provider at this pointbecause it might have
|
||||||
|
// already been destroyed.
|
||||||
|
|
||||||
|
QString name;
|
||||||
|
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex_);
|
QMutexLocker locker(&mutex_);
|
||||||
cover_providers_.removeAll(provider);
|
name = cover_providers_.take(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.isNull()) {
|
||||||
|
qLog(Debug) << "Tried to remove a cover provider that was not registered";
|
||||||
|
} else {
|
||||||
|
qLog(Debug) << "Unregistered cover provider" << name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#ifndef COVERPROVIDERS_H
|
#ifndef COVERPROVIDERS_H
|
||||||
#define COVERPROVIDERS_H
|
#define COVERPROVIDERS_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public:
|
|||||||
void RemoveProvider(CoverProvider* provider);
|
void RemoveProvider(CoverProvider* provider);
|
||||||
|
|
||||||
// Returns a list of cover providers
|
// Returns a list of cover providers
|
||||||
QList<CoverProvider*> List() const { return cover_providers_; }
|
QList<CoverProvider*> List() const { return cover_providers_.keys(); }
|
||||||
// Returns true if this repository has at least one registered provider.
|
// Returns true if this repository has at least one registered provider.
|
||||||
bool HasAnyProviders() const { return !cover_providers_.isEmpty(); }
|
bool HasAnyProviders() const { return !cover_providers_.isEmpty(); }
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ private:
|
|||||||
~CoverProviders() {}
|
~CoverProviders() {}
|
||||||
Q_DISABLE_COPY(CoverProviders);
|
Q_DISABLE_COPY(CoverProviders);
|
||||||
|
|
||||||
QList<CoverProvider*> cover_providers_;
|
QMap<CoverProvider*, QString> cover_providers_;
|
||||||
QMutex mutex_;
|
QMutex mutex_;
|
||||||
|
|
||||||
QAtomicInt next_id_;
|
QAtomicInt next_id_;
|
||||||
|
Loading…
Reference in New Issue
Block a user