From 5ee4fb3522ea2bb66ad49e1cdd91140b8d5c6a00 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 11 Nov 2022 15:02:08 +0100 Subject: feat: validate maximum memory allocation Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/global/JavaPage.cpp | 25 ++++++- launcher/ui/pages/global/JavaPage.h | 3 + launcher/ui/pages/global/JavaPage.ui | 54 ++++++++------ .../ui/pages/instance/InstanceSettingsPage.cpp | 26 ++++++- launcher/ui/pages/instance/InstanceSettingsPage.h | 3 + launcher/ui/pages/instance/InstanceSettingsPage.ui | 87 +++++++++++++--------- 6 files changed, 135 insertions(+), 63 deletions(-) diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index 2cee15bf..00c06cff 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -58,9 +58,8 @@ JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage) ui->setupUi(this); ui->tabWidget->tabBar()->hide(); - auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; - ui->maxMemSpinBox->setMaximum(sysMiB); loadSettings(); + updateThresholds(); } JavaPage::~JavaPage() @@ -177,6 +176,11 @@ void JavaPage::on_javaTestBtn_clicked() checker->run(); } +void JavaPage::on_maxMemSpinBox_valueChanged(int i) +{ + updateThresholds(); +} + void JavaPage::checkerFinished() { checker.reset(); @@ -186,3 +190,20 @@ void JavaPage::retranslate() { ui->retranslateUi(this); } + +void JavaPage::updateThresholds() +{ + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + unsigned int maxMem = ui->maxMemSpinBox->value(); + + if (maxMem >= sysMiB) { + ui->labelMaxMemIcon->setText(u8"✘"); + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); + } else if (maxMem > (sysMiB * 0.9)) { + ui->labelMaxMemIcon->setText(u8"⚠"); + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); + } else { + ui->labelMaxMemIcon->setText(u8"✔"); + ui->labelMaxMemIcon->setToolTip(""); + } +} diff --git a/launcher/ui/pages/global/JavaPage.h b/launcher/ui/pages/global/JavaPage.h index 64d4098e..2ef6d749 100644 --- a/launcher/ui/pages/global/JavaPage.h +++ b/launcher/ui/pages/global/JavaPage.h @@ -76,6 +76,8 @@ public: bool apply() override; void retranslate() override; + void updateThresholds(); + private: void applySettings(); void loadSettings(); @@ -85,6 +87,7 @@ slots: void on_javaDetectBtn_clicked(); void on_javaTestBtn_clicked(); void on_javaBrowseBtn_clicked(); + void on_maxMemSpinBox_valueChanged(int i); void checkerFinished(); private: diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui index 6ccffed4..19e23eba 100644 --- a/launcher/ui/pages/global/JavaPage.ui +++ b/launcher/ui/pages/global/JavaPage.ui @@ -44,8 +44,8 @@ Memory - - + + The maximum amount of memory Minecraft is allowed to use. @@ -67,27 +67,17 @@ - - - - &Minimum memory allocation: - - - minMemSpinBox - - - - - + + - Ma&ximum memory allocation: + &PermGen: - maxMemSpinBox + permGenSpinBox - + The amount of memory Minecraft is started with. @@ -109,17 +99,27 @@ - - + + - &PermGen: + Ma&ximum memory allocation: - permGenSpinBox + maxMemSpinBox + + + + + + + &Minimum memory allocation: + + + minMemSpinBox - + The amount of memory available to store loaded Java classes. @@ -141,6 +141,16 @@ + + + + + + + maxMemSpinBox + + + diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 5da7f19f..50039e87 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -59,12 +59,12 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent) { m_settings = inst->settings(); ui->setupUi(this); - auto sysMB = Sys::getSystemRam() / Sys::mebibyte; - ui->maxMemSpinBox->setMaximum(sysMB); + connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked); connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings); connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings); loadSettings(); + updateThresholds(); } bool InstanceSettingsPage::shouldDisplay() const @@ -437,6 +437,11 @@ void InstanceSettingsPage::on_javaTestBtn_clicked() checker->run(); } +void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i) +{ + updateThresholds(); +} + void InstanceSettingsPage::checkerFinished() { checker.reset(); @@ -447,3 +452,20 @@ void InstanceSettingsPage::retranslate() ui->retranslateUi(this); ui->customCommands->retranslate(); // TODO: why is this seperate from the others? } + +void InstanceSettingsPage::updateThresholds() +{ + auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; + unsigned int maxMem = ui->maxMemSpinBox->value(); + + if (maxMem >= sysMiB) { + ui->labelMaxMemIcon->setText(u8"✘"); + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); + } else if (maxMem > (sysMiB * 0.9)) { + ui->labelMaxMemIcon->setText(u8"⚠"); + ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); + } else { + ui->labelMaxMemIcon->setText(u8"✔"); + ui->labelMaxMemIcon->setToolTip(""); + } +} diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h index 97d1296f..7450188d 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.h +++ b/launcher/ui/pages/instance/InstanceSettingsPage.h @@ -77,10 +77,13 @@ public: virtual bool shouldDisplay() const override; void retranslate() override; + void updateThresholds(); + private slots: void on_javaDetectBtn_clicked(); void on_javaTestBtn_clicked(); void on_javaBrowseBtn_clicked(); + void on_maxMemSpinBox_valueChanged(int i); void applySettings(); void loadSettings(); diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 8b3c3370..43488aa2 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -112,40 +112,54 @@ false - - - + + + - Minimum memory allocation: + PermGen: - - + + + + Maximum memory allocation: + + + + + + + Note: Permgen is set automatically by Java 8 and later + + + + + - The maximum amount of memory Minecraft is allowed to use. + The amount of memory available to store loaded Java classes. MiB - 128 + 64 - 65536 + 999999999 - 128 + 8 - 1024 + 64 - - + + - The amount of memory Minecraft is started with. + The maximum amount of memory Minecraft is allowed to use. MiB @@ -160,50 +174,49 @@ 128 - 256 + 1024 - - + + + + Minimum memory allocation: + + + + + - The amount of memory available to store loaded Java classes. + The amount of memory Minecraft is started with. MiB - 64 + 128 - 999999999 + 65536 - 8 + 128 - 64 + 256 - - + + - PermGen: + - - - - - - Maximum memory allocation: + + Qt::AlignCenter - - - - - - Note: Permgen is set automatically by Java 8 and later + + maxMemSpinBox -- cgit From 863a168cb5cb7332ae9782c3967d563f7f98316d Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 11 Nov 2022 15:04:18 +0100 Subject: feat: raise memory limits to 1TiB Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/global/JavaPage.ui | 4 ++-- launcher/ui/pages/instance/InstanceSettingsPage.ui | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui index 19e23eba..73461237 100644 --- a/launcher/ui/pages/global/JavaPage.ui +++ b/launcher/ui/pages/global/JavaPage.ui @@ -57,7 +57,7 @@ 128 - 65536 + 1048576 128 @@ -89,7 +89,7 @@ 128 - 65536 + 1048576 128 diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 43488aa2..2063dc55 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -168,7 +168,7 @@ 128 - 65536 + 1048576 128 @@ -197,7 +197,7 @@ 128 - 65536 + 1048576 128 -- cgit From cabd887866929103f635a2640589ce95570f8573 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 11 Nov 2022 15:22:16 +0100 Subject: feat: use icons to show memory allocation state Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/global/JavaPage.cpp | 15 ++++++++++++--- launcher/ui/pages/instance/InstanceSettingsPage.cpp | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index 00c06cff..81dd4cc1 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -196,14 +196,23 @@ void JavaPage::updateThresholds() auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; unsigned int maxMem = ui->maxMemSpinBox->value(); + QString iconName; + if (maxMem >= sysMiB) { - ui->labelMaxMemIcon->setText(u8"✘"); + iconName = "status-bad"; ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); } else if (maxMem > (sysMiB * 0.9)) { - ui->labelMaxMemIcon->setText(u8"⚠"); + iconName = "status-yellow"; ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); } else { - ui->labelMaxMemIcon->setText(u8"✔"); + iconName = "status-good"; ui->labelMaxMemIcon->setToolTip(""); } + + { + auto height = ui->labelMaxMemIcon->fontInfo().pixelSize(); + QIcon icon = APPLICATION->getThemedIcon(iconName); + QPixmap pix = icon.pixmap(height, height); + ui->labelMaxMemIcon->setPixmap(pix); + } } diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp index 50039e87..af2ba7c8 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp +++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp @@ -458,14 +458,23 @@ void InstanceSettingsPage::updateThresholds() auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; unsigned int maxMem = ui->maxMemSpinBox->value(); + QString iconName; + if (maxMem >= sysMiB) { - ui->labelMaxMemIcon->setText(u8"✘"); + iconName = "status-bad"; ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); } else if (maxMem > (sysMiB * 0.9)) { - ui->labelMaxMemIcon->setText(u8"⚠"); + iconName = "status-yellow"; ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); } else { - ui->labelMaxMemIcon->setText(u8"✔"); + iconName = "status-good"; ui->labelMaxMemIcon->setToolTip(""); } + + { + auto height = ui->labelMaxMemIcon->fontInfo().pixelSize(); + QIcon icon = APPLICATION->getThemedIcon(iconName); + QPixmap pix = icon.pixmap(height, height); + ui->labelMaxMemIcon->setPixmap(pix); + } } -- cgit From b57fee1a444bef22f6a0f8f268dc1d11be31a0db Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 11 Nov 2022 15:24:14 +0100 Subject: fix: swap spin box and state icon Signed-off-by: Sefa Eyeoglu --- launcher/ui/pages/global/JavaPage.ui | 68 +++++++++++----------- launcher/ui/pages/instance/InstanceSettingsPage.ui | 46 +++++++-------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/launcher/ui/pages/global/JavaPage.ui b/launcher/ui/pages/global/JavaPage.ui index 73461237..6749cbe4 100644 --- a/launcher/ui/pages/global/JavaPage.ui +++ b/launcher/ui/pages/global/JavaPage.ui @@ -44,26 +44,14 @@ Memory - - - - - The maximum amount of memory Minecraft is allowed to use. - - - MiB - - - 128 - - - 1048576 - - - 128 + + + + + Ma&ximum memory allocation: - - 1024 + + maxMemSpinBox @@ -77,6 +65,16 @@ + + + + &Minimum memory allocation: + + + minMemSpinBox + + + @@ -99,23 +97,25 @@ - - - - Ma&ximum memory allocation: + + + + The maximum amount of memory Minecraft is allowed to use. - - maxMemSpinBox + + MiB - - - - - - &Minimum memory allocation: + + 128 - - minMemSpinBox + + 1048576 + + + 128 + + + 1024 @@ -141,7 +141,7 @@ - + diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui index 2063dc55..b064367d 100644 --- a/launcher/ui/pages/instance/InstanceSettingsPage.ui +++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui @@ -112,7 +112,7 @@ false - + @@ -120,6 +120,13 @@ + + + + Minimum memory allocation: + + + @@ -134,25 +141,25 @@ - - + + - The amount of memory available to store loaded Java classes. + The amount of memory Minecraft is started with. MiB - 64 + 128 - 999999999 + 1048576 - 8 + 128 - 64 + 256 @@ -178,36 +185,29 @@ - - - - Minimum memory allocation: - - - - - + + - The amount of memory Minecraft is started with. + The amount of memory available to store loaded Java classes. MiB - 128 + 64 - 1048576 + 999999999 - 128 + 8 - 256 + 64 - + -- cgit From 884fe0d5741de2a8a78f48c5d37274d8f174ba3a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 20 Nov 2022 18:16:19 +0100 Subject: feat: validate maximum memory allocation in wizard Signed-off-by: Sefa Eyeoglu --- launcher/ui/widgets/JavaSettingsWidget.cpp | 42 +++++++++++++++++++++++++----- launcher/ui/widgets/JavaSettingsWidget.h | 9 ++++--- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index c7c4dbbd..15994319 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -71,6 +71,7 @@ void JavaSettingsWidget::setupUi() m_memoryGroupBox->setObjectName(QStringLiteral("memoryGroupBox")); m_gridLayout_2 = new QGridLayout(m_memoryGroupBox); m_gridLayout_2->setObjectName(QStringLiteral("gridLayout_2")); + m_gridLayout_2->setColumnStretch(0, 1); m_labelMinMem = new QLabel(m_memoryGroupBox); m_labelMinMem->setObjectName(QStringLiteral("labelMinMem")); @@ -80,7 +81,7 @@ void JavaSettingsWidget::setupUi() m_minMemSpinBox->setObjectName(QStringLiteral("minMemSpinBox")); m_minMemSpinBox->setSuffix(QStringLiteral(" MiB")); m_minMemSpinBox->setMinimum(128); - m_minMemSpinBox->setMaximum(m_availableMemory); + m_minMemSpinBox->setMaximum(1048576); m_minMemSpinBox->setSingleStep(128); m_labelMinMem->setBuddy(m_minMemSpinBox); m_gridLayout_2->addWidget(m_minMemSpinBox, 0, 1, 1, 1); @@ -93,11 +94,15 @@ void JavaSettingsWidget::setupUi() m_maxMemSpinBox->setObjectName(QStringLiteral("maxMemSpinBox")); m_maxMemSpinBox->setSuffix(QStringLiteral(" MiB")); m_maxMemSpinBox->setMinimum(128); - m_maxMemSpinBox->setMaximum(m_availableMemory); + m_maxMemSpinBox->setMaximum(1048576); m_maxMemSpinBox->setSingleStep(128); m_labelMaxMem->setBuddy(m_maxMemSpinBox); m_gridLayout_2->addWidget(m_maxMemSpinBox, 1, 1, 1, 1); + m_labelMaxMemIcon = new QLabel(m_memoryGroupBox); + m_labelMaxMemIcon->setObjectName(QStringLiteral("labelMaxMemIcon")); + m_gridLayout_2->addWidget(m_labelMaxMemIcon, 1, 2, 1, 1); + m_labelPermGen = new QLabel(m_memoryGroupBox); m_labelPermGen->setObjectName(QStringLiteral("labelPermGen")); m_labelPermGen->setText(QStringLiteral("PermGen:")); @@ -108,7 +113,7 @@ void JavaSettingsWidget::setupUi() m_permGenSpinBox->setObjectName(QStringLiteral("permGenSpinBox")); m_permGenSpinBox->setSuffix(QStringLiteral(" MiB")); m_permGenSpinBox->setMinimum(64); - m_permGenSpinBox->setMaximum(m_availableMemory); + m_permGenSpinBox->setMaximum(1048576); m_permGenSpinBox->setSingleStep(8); m_gridLayout_2->addWidget(m_permGenSpinBox, 2, 1, 1, 1); m_permGenSpinBox->setVisible(false); @@ -130,6 +135,7 @@ void JavaSettingsWidget::initialize() m_minMemSpinBox->setValue(observedMinMemory); m_maxMemSpinBox->setValue(observedMaxMemory); m_permGenSpinBox->setValue(observedPermGenMemory); + updateThresholds(); } void JavaSettingsWidget::refresh() @@ -210,9 +216,9 @@ int JavaSettingsWidget::permGenSize() const void JavaSettingsWidget::memoryValueChanged(int) { bool actuallyChanged = false; - int min = m_minMemSpinBox->value(); - int max = m_maxMemSpinBox->value(); - int permgen = m_permGenSpinBox->value(); + unsigned int min = m_minMemSpinBox->value(); + unsigned int max = m_maxMemSpinBox->value(); + unsigned int permgen = m_permGenSpinBox->value(); QObject *obj = sender(); if (obj == m_minMemSpinBox && min != observedMinMemory) { @@ -242,6 +248,7 @@ void JavaSettingsWidget::memoryValueChanged(int) if(actuallyChanged) { checkJavaPathOnEdit(m_javaPathTextBox->text()); + updateThresholds(); } } @@ -435,3 +442,26 @@ void JavaSettingsWidget::retranslate() m_permGenSpinBox->setToolTip(tr("The amount of memory available to store loaded Java classes.")); m_javaBrowseBtn->setText(tr("Browse")); } + +void JavaSettingsWidget::updateThresholds() +{ + QString iconName; + + if (observedMaxMemory >= m_availableMemory) { + iconName = "status-bad"; + m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity.")); + } else if (observedMaxMemory > (m_availableMemory * 0.9)) { + iconName = "status-yellow"; + m_labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity.")); + } else { + iconName = "status-good"; + m_labelMaxMemIcon->setToolTip(""); + } + + { + auto height = m_labelMaxMemIcon->fontInfo().pixelSize(); + QIcon icon = APPLICATION->getThemedIcon(iconName); + QPixmap pix = icon.pixmap(height, height); + m_labelMaxMemIcon->setPixmap(pix); + } +} diff --git a/launcher/ui/widgets/JavaSettingsWidget.h b/launcher/ui/widgets/JavaSettingsWidget.h index 5344e2cd..e4b7c712 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.h +++ b/launcher/ui/widgets/JavaSettingsWidget.h @@ -56,6 +56,8 @@ public: int maxHeapSize() const; QString javaPath() const; + void updateThresholds(); + protected slots: void memoryValueChanged(int); @@ -85,6 +87,7 @@ private: /* data */ QSpinBox *m_maxMemSpinBox = nullptr; QLabel *m_labelMinMem = nullptr; QLabel *m_labelMaxMem = nullptr; + QLabel *m_labelMaxMemIcon = nullptr; QSpinBox *m_minMemSpinBox = nullptr; QLabel *m_labelPermGen = nullptr; QSpinBox *m_permGenSpinBox = nullptr; @@ -92,9 +95,9 @@ private: /* data */ QIcon yellowIcon; QIcon badIcon; - int observedMinMemory = 0; - int observedMaxMemory = 0; - int observedPermGenMemory = 0; + unsigned int observedMinMemory = 0; + unsigned int observedMaxMemory = 0; + unsigned int observedPermGenMemory = 0; QString queuedCheck; uint64_t m_availableMemory = 0ull; shared_qobject_ptr m_checker; -- cgit