Compare commits

...

4 Commits

Author SHA1 Message Date
maurycyliebner
6dd0f78f51 Fix permanent critical memory state. 2022-01-06 15:25:36 +01:00
maurycyliebner
e88e48fca6 Check if image handler exists before replacing image. 2022-01-06 15:12:05 +01:00
maurycyliebner
57cf06d606 Add clear memory button. 2022-01-06 15:08:31 +01:00
maurycyliebner
0117c34d84 Improve low memory handling while rendering. 2022-01-06 14:44:41 +01:00
6 changed files with 24 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include "Private/Tasks/taskscheduler.h" #include "Private/Tasks/taskscheduler.h"
#include "Private/Tasks/complextask.h" #include "Private/Tasks/complextask.h"
#include "conncontextptr.h" #include "conncontextptr.h"
#include "memoryhandler.h"
#include <QTimer> #include <QTimer>
#include <QLocale> #include <QLocale>
@ -146,6 +147,13 @@ UsageWidget::UsageWidget(QWidget * const parent) : QStatusBar(parent) {
mRamLabel = new QLabel(this); mRamLabel = new QLabel(this);
const auto clearRamButton = new QPushButton("clear memory", this);
connect(clearRamButton, &QPushButton::clicked,
this, []() {
const auto m = MemoryHandler::sInstance;
m->clearMemory();
});
addPermanentWidget(gpuLabel); addPermanentWidget(gpuLabel);
addPermanentWidget(mGpuBar); addPermanentWidget(mGpuBar);
@ -160,6 +168,8 @@ UsageWidget::UsageWidget(QWidget * const parent) : QStatusBar(parent) {
addPermanentWidget(mRamLabel); addPermanentWidget(mRamLabel);
addPermanentWidget(clearRamButton);
setThreadsTotal(QThread::idealThreadCount()); setThreadsTotal(QThread::idealThreadCount());
connect(TaskScheduler::instance(), &TaskScheduler::hddUsageChanged, connect(TaskScheduler::instance(), &TaskScheduler::hddUsageChanged,
@ -200,7 +210,7 @@ void UsageWidget::setTotalRam(const qreal totalRamMB) {
} }
void UsageWidget::addComplexTask(ComplexTask * const task) { void UsageWidget::addComplexTask(ComplexTask * const task) {
for(const auto wid : mTaskWidgets) { for(const auto wid : qAsConst(mTaskWidgets)) {
if(wid->isHidden()) { if(wid->isHidden()) {
return wid->setComplexTask(task); return wid->setComplexTask(task);
} }

View File

@ -164,7 +164,7 @@ void MemoryChecker::checkMemory() {
} else if(procFreeKB.fValue < 0) { } else if(procFreeKB.fValue < 0) {
emit handleMemoryState(LOW_MEMORY_STATE, longB(-procFreeKB)); emit handleMemoryState(LOW_MEMORY_STATE, longB(-procFreeKB));
mLastMemoryState = LOW_MEMORY_STATE; mLastMemoryState = LOW_MEMORY_STATE;
} else if(mLastMemoryState != NORMAL_MEMORY_STATE) { } else/* if(mLastMemoryState != NORMAL_MEMORY_STATE)*/ {
emit handleMemoryState(NORMAL_MEMORY_STATE, longB(0)); emit handleMemoryState(NORMAL_MEMORY_STATE, longB(0));
mLastMemoryState = NORMAL_MEMORY_STATE; mLastMemoryState = NORMAL_MEMORY_STATE;
} }

View File

@ -60,6 +60,10 @@ MemoryHandler::~MemoryHandler() {
delete mMemoryChecker; delete mMemoryChecker;
} }
void MemoryHandler::clearMemory() {
freeMemory(NORMAL_MEMORY_STATE, longB(std::numeric_limits<qint64>::max()));
}
MemoryState MemoryHandler::sMemoryState() { MemoryState MemoryHandler::sMemoryState() {
return sInstance->mMemoryState; return sInstance->mMemoryState;
} }
@ -90,11 +94,11 @@ void MemoryHandler::freeMemory(const MemoryState newState,
const auto cont = mDataHandler.takeFirst(); const auto cont = mDataHandler.takeFirst();
memToFree -= cont->free_RAM_k(); memToFree -= cont->free_RAM_k();
} }
if(newState == CRITICAL_MEMORY_STATE) { if(newState == CRITICAL_MEMORY_STATE ||
memToFree > 0) {
mMemoryState = CRITICAL_MEMORY_STATE;
emit enteredCriticalState(); emit enteredCriticalState();
emit allMemoryUsed(); emit allMemoryUsed();
} else if(memToFree > 0) {
emit allMemoryUsed();
} }
emit memoryFreed(); emit memoryFreed();
} }

View File

@ -26,6 +26,8 @@ public:
explicit MemoryHandler(QObject * const parent = nullptr); explicit MemoryHandler(QObject * const parent = nullptr);
~MemoryHandler(); ~MemoryHandler();
void clearMemory();
static MemoryHandler *sInstance; static MemoryHandler *sInstance;
static MemoryState sMemoryState(); static MemoryState sMemoryState();
signals: signals:

View File

@ -89,11 +89,11 @@ void ImageLoader::process() {
} }
void ImageLoader::afterProcessing() { void ImageLoader::afterProcessing() {
mTargetHandler->replaceImage(mImage); if(mTargetHandler) mTargetHandler->replaceImage(mImage);
} }
void ImageLoader::afterCanceled() { void ImageLoader::afterCanceled() {
mTargetHandler->replaceImage(mImage); if(mTargetHandler) mTargetHandler->replaceImage(mImage);
} }
void OraLoader::process() { void OraLoader::process() {

View File

@ -33,7 +33,7 @@ public:
void afterProcessing(); void afterProcessing();
void afterCanceled(); void afterCanceled();
protected: protected:
ImageFileDataHandler * const mTargetHandler; const qptr<ImageFileDataHandler> mTargetHandler;
const QString mFilePath; const QString mFilePath;
sk_sp<SkImage> mImage; sk_sp<SkImage> mImage;
}; };