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 --- .../ui/pages/instance/InstanceSettingsPage.cpp | 26 ++++++- launcher/ui/pages/instance/InstanceSettingsPage.h | 3 + launcher/ui/pages/instance/InstanceSettingsPage.ui | 87 +++++++++++++--------- 3 files changed, 77 insertions(+), 39 deletions(-) (limited to 'launcher/ui/pages/instance') 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