feat: validate maximum memory allocation

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-11-11 15:02:08 +01:00
parent 46a8e18841
commit 5ee4fb3522
No known key found for this signature in database
GPG Key ID: C10411294912A422
6 changed files with 151 additions and 79 deletions

View File

@ -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("");
}
}

View File

@ -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:

View File

@ -44,8 +44,8 @@
<property name="title">
<string>Memory</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0">
<item row="1" column="2">
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
@ -67,27 +67,17 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<property name="text">
<string>&amp;Minimum memory allocation:</string>
<string notr="true">&amp;PermGen:</string>
</property>
<property name="buddy">
<cstring>minMemSpinBox</cstring>
<cstring>permGenSpinBox</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>Ma&amp;ximum memory allocation:</string>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QSpinBox" name="minMemSpinBox">
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
@ -109,17 +99,27 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string notr="true">&amp;PermGen:</string>
<string>Ma&amp;ximum memory allocation:</string>
</property>
<property name="buddy">
<cstring>permGenSpinBox</cstring>
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<property name="text">
<string>&amp;Minimum memory allocation:</string>
</property>
<property name="buddy">
<cstring>minMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="permGenSpinBox">
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
@ -141,6 +141,16 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelMaxMemIcon">
<property name="text">
<string/>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -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("");
}
}

View File

@ -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();

View File

@ -112,59 +112,29 @@
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0">
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<property name="text">
<string>Minimum memory allocation:</string>
<string notr="true">PermGen:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>128</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>Maximum memory allocation:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="minMemSpinBox">
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>128</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="labelPermgenNote">
<property name="text">
<string>Note: Permgen is set automatically by Java 8 and later</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="2">
<widget class="QSpinBox" name="permGenSpinBox">
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
@ -186,24 +156,67 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<property name="text">
<string notr="true">PermGen:</string>
<item row="1" column="2">
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>128</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<property name="text">
<string>Maximum memory allocation:</string>
<string>Minimum memory allocation:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="labelPermgenNote">
<item row="0" column="2">
<widget class="QSpinBox" name="minMemSpinBox">
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>128</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelMaxMemIcon">
<property name="text">
<string>Note: Permgen is set automatically by Java 8 and later</string>
<string notr="true"/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>