Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Fix crash at exit by allocating QObjects on the heap #303

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 6 additions & 8 deletions src/model/badgecontainer.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#include "badgecontainer.h"
#include "settingsmanager.h"

BadgeContainer *BadgeContainer::instance = 0;
BadgeContainer *BadgeContainer::getInstance()
{
if (!instance)
instance = new BadgeContainer();
return instance;
}

BadgeContainer::BadgeContainer() : netman(NetworkManager::getInstance())
{
connect(netman, &NetworkManager::getEmoteSetsOperationFinished, this, &BadgeContainer::onEmoteSetsUpdated);
Expand All @@ -23,6 +15,12 @@ BadgeContainer::BadgeContainer() : netman(NetworkManager::getInstance())
connect(netman, &NetworkManager::getChannelBttvEmotesOperationFinished, this, &BadgeContainer::innerChannelBttvEmotesLoaded);
}

BadgeContainer *BadgeContainer::getInstance()
{
static BadgeContainer *instance = new BadgeContainer();
return instance;
}

bool BadgeContainer::getChannelBadgeUrl(const QString channelId, const QString badgeName, const QString imageFormat, QString &outUrl) const {
auto channelEntry = channelBadgeUrls.find(channelId);
if (channelEntry != channelBadgeUrls.end()) {
Expand Down
5 changes: 1 addition & 4 deletions src/model/channelmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "channelmanager.h"
#include <QCoreApplication>

ChannelManager *ChannelManager::instance = 0;

ChannelManager::ChannelManager() :
netman(NetworkManager::getInstance()),
settingsManager(SettingsManager::getInstance())
Expand Down Expand Up @@ -63,8 +61,7 @@ ChannelManager::ChannelManager() :
}

ChannelManager *ChannelManager::getInstance() {
if (!instance)
instance = new ChannelManager();
static ChannelManager *instance = new ChannelManager();
return instance;
}

Expand Down
1 change: 0 additions & 1 deletion src/model/channelmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ChannelManager: public QObject
ChannelListModel *createFollowedChannelsModel();
bool isAccessTokenAvailable() { return settingsManager->hasAccessToken(); }

static ChannelManager *instance;
ChannelManager();

public:
Expand Down
5 changes: 3 additions & 2 deletions src/model/imageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
const int ImageProvider::MSEC_PER_DOWNLOAD = 16; // ~ 256kbit/sec for 2k images

ImageProvider::ImageProvider(const QString imageProviderName, const QString extension, const QString cacheDirName) : QObject(),
_cacheProvider(this), _imageProviderName(imageProviderName), _extension(extension) {
_imageProviderName(imageProviderName), _extension(extension) {
_cacheProvider = new CachedImageProvider(this);

activeDownloadCount = 0;

Expand Down Expand Up @@ -158,7 +159,7 @@ void ImageProvider::loadImageFile(QString emoteKey, QString filename) {
}

QQmlImageProviderBase * ImageProvider::getQMLImageProvider() {
return &_cacheProvider;
return _cacheProvider;
}

bool ImageProvider::downloadsInProgress() const {
Expand Down
2 changes: 1 addition & 1 deletion src/model/imageprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected slots:
QNetworkAccessManager _manager;

friend class CachedImageProvider;
CachedImageProvider _cacheProvider;
CachedImageProvider *_cacheProvider;

QHash<QString, QImage> _imageTable;
QString _imageProviderName;
Expand Down
4 changes: 2 additions & 2 deletions src/model/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ SettingsManager::SettingsManager(QObject *parent) :

SettingsManager *SettingsManager::getInstance()
{
static SettingsManager instance;
return &instance;
static SettingsManager *instance = new SettingsManager();
return instance;
}

void SettingsManager::load()
Expand Down
7 changes: 5 additions & 2 deletions src/model/viewersmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "viewersmodel.h"

ViewersModel *ViewersModel::instance = 0;

ViewersModel::ViewersModel(QObject *parent) : QObject(parent), netman(NetworkManager::getInstance())
{
connect(netman, &NetworkManager::chatterListLoadOperationFinished, this, &ViewersModel::processChatterList);
}

ViewersModel *ViewersModel::getInstance() {
static ViewersModel *instance = new ViewersModel();
return instance;
}

void ViewersModel::processChatterList(QMap<QString, QList<QString>> chatters)
{
QVariantMap out;
Expand Down
6 changes: 1 addition & 5 deletions src/model/viewersmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class ViewersModel : public QObject
explicit ViewersModel(QObject *parent = nullptr);

public:
static ViewersModel *getInstance() {
if (!instance)
instance = new ViewersModel();
return instance;
}
static ViewersModel *getInstance();

signals:
void chatterListLoaded(QVariantMap chatters);
Expand Down
8 changes: 2 additions & 6 deletions src/model/vodmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@ VodManager::VodManager(QObject *parent) :
settings.endArray();

emit modelChanged();

std::atexit([](){
VodManager::getInstance()->saveSettings();
});
}

VodManager *VodManager::getInstance() {
static VodManager instance;
return &instance;
static VodManager *instance = new VodManager();
return instance;
}

VodManager::~VodManager()
Expand Down
5 changes: 1 addition & 4 deletions src/network/httpserver.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include "httpserver.h"

HttpServer *HttpServer::instance = 0;

HttpServer::HttpServer(QObject *parent): QObject(parent)
{

}

HttpServer *HttpServer::getInstance() {
if (!instance)
instance = new HttpServer();
static HttpServer *instance = new HttpServer();
return instance;
}

Expand Down
2 changes: 0 additions & 2 deletions src/network/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class HttpServer: public QObject
bool listenError = false;
QString m_port;

static HttpServer *instance;

explicit HttpServer(QObject *parent = 0);
public:
static HttpServer *getInstance();
Expand Down
5 changes: 1 addition & 4 deletions src/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include <QtAndroidExtras>
#endif

Power *Power::instance = 0;

Power::Power() :
cookie(0)
{
Expand All @@ -41,8 +39,7 @@ Power::Power() :

Power *Power::getInstance()
{
if (!instance)
instance = new Power();
static Power *instance = new Power();
return instance;
}

Expand Down
1 change: 0 additions & 1 deletion src/power/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Power: public QObject

Q_PROPERTY(bool screensaver WRITE setScreensaver)

static Power *instance;
Power();

public:
Expand Down