From 9a2d203c0d95e51ea02e3e62fef6289973777e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 27 Sep 2017 12:45:07 +0200 Subject: [PATCH] GH-1993 swap min/max memory settings when they are the wrong way around --- api/logic/minecraft/MinecraftInstance.cpp | 14 +++++++++-- application/MultiMC.cpp | 15 ++++++++++-- application/pages/InstanceSettingsPage.cpp | 28 ++++++++++++++++++---- application/pages/global/JavaPage.cpp | 28 ++++++++++++++++++---- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index 4ff85c27b..14de2f5f8 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -305,8 +305,18 @@ QStringList MinecraftInstance::javaArguments() const "minecraft.exe.heapdump"); #endif - args << QString("-Xms%1m").arg(settings()->get("MinMemAlloc").toInt()); - args << QString("-Xmx%1m").arg(settings()->get("MaxMemAlloc").toInt()); + int min = settings()->get("MinMemAlloc").toInt(); + int max = settings()->get("MaxMemAlloc").toInt(); + if(min < max) + { + args << QString("-Xms%1m").arg(min); + args << QString("-Xmx%1m").arg(max); + } + else + { + args << QString("-Xms%1m").arg(max); + args << QString("-Xmx%1m").arg(min); + } // No PermGen in newer java. JavaVersion javaVersion = getJavaVersion(); diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index fd004b05a..feaf88a74 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -1125,8 +1125,19 @@ MainWindow* MultiMC::showMainWindow(bool minimized) * cd4 = CPU architecture */ QVariantMap customValues; - customValues["cm1"] = m_settings->get("MinMemAlloc"); - customValues["cm2"] = m_settings->get("MaxMemAlloc"); + int min = m_settings->get("MinMemAlloc").toInt(); + int max = m_settings->get("MaxMemAlloc").toInt(); + if(min < max) + { + customValues["cm1"] = min; + customValues["cm2"] = max; + } + else + { + customValues["cm1"] = max; + customValues["cm2"] = min; + } + constexpr uint64_t Mega = 1024ull * 1024ull; int ramSize = int(Sys::getSystemRam() / Mega); qDebug() << "RAM size is" << ramSize << "MB"; diff --git a/application/pages/InstanceSettingsPage.cpp b/application/pages/InstanceSettingsPage.cpp index 22dbd81f5..90c2e92ed 100644 --- a/application/pages/InstanceSettingsPage.cpp +++ b/application/pages/InstanceSettingsPage.cpp @@ -80,8 +80,18 @@ void InstanceSettingsPage::applySettings() m_settings->set("OverrideMemory", memory); if (memory) { - m_settings->set("MinMemAlloc", ui->minMemSpinBox->value()); - m_settings->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + int min = ui->minMemSpinBox->value(); + int max = ui->maxMemSpinBox->value(); + if(min < max) + { + m_settings->set("MinMemAlloc", min); + m_settings->set("MaxMemAlloc", max); + } + else + { + m_settings->set("MinMemAlloc", max); + m_settings->set("MaxMemAlloc", min); + } m_settings->set("PermGen", ui->permGenSpinBox->value()); } else @@ -152,8 +162,18 @@ void InstanceSettingsPage::loadSettings() // Memory ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool()); - ui->minMemSpinBox->setValue(m_settings->get("MinMemAlloc").toInt()); - ui->maxMemSpinBox->setValue(m_settings->get("MaxMemAlloc").toInt()); + int min = m_settings->get("MinMemAlloc").toInt(); + int max = m_settings->get("MaxMemAlloc").toInt(); + if(min < max) + { + ui->minMemSpinBox->setValue(min); + ui->maxMemSpinBox->setValue(max); + } + else + { + ui->minMemSpinBox->setValue(max); + ui->maxMemSpinBox->setValue(min); + } ui->permGenSpinBox->setValue(m_settings->get("PermGen").toInt()); // Java Settings diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp index f43fd6412..81c6f7a74 100644 --- a/application/pages/global/JavaPage.cpp +++ b/application/pages/global/JavaPage.cpp @@ -62,8 +62,18 @@ void JavaPage::applySettings() auto s = MMC->settings(); // Memory - s->set("MinMemAlloc", ui->minMemSpinBox->value()); - s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + int min = ui->minMemSpinBox->value(); + int max = ui->maxMemSpinBox->value(); + if(min < max) + { + s->set("MinMemAlloc", min); + s->set("MaxMemAlloc", max); + } + else + { + s->set("MinMemAlloc", max); + s->set("MaxMemAlloc", min); + } s->set("PermGen", ui->permGenSpinBox->value()); // Java Settings @@ -80,8 +90,18 @@ void JavaPage::loadSettings() { auto s = MMC->settings(); // Memory - ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt()); - ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); + int min = s->get("MinMemAlloc").toInt(); + int max = s->get("MaxMemAlloc").toInt(); + if(min < max) + { + ui->minMemSpinBox->setValue(min); + ui->maxMemSpinBox->setValue(max); + } + else + { + ui->minMemSpinBox->setValue(max); + ui->maxMemSpinBox->setValue(min); + } ui->permGenSpinBox->setValue(s->get("PermGen").toInt()); // Java Settings