mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Avoid division by zero
This commit is contained in:
parent
41c78a889a
commit
b96929f3fc
@ -20,6 +20,9 @@
|
||||
QString getAspect(int x, int y)
|
||||
{
|
||||
int gcd = std::gcd (x, y);
|
||||
if (gcd == 0)
|
||||
return QString();
|
||||
|
||||
int xaspect = x / gcd;
|
||||
int yaspect = y / gcd;
|
||||
// special case: 8 : 5 is usually referred to as 16:10
|
||||
@ -298,9 +301,9 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
|
||||
return result;
|
||||
}
|
||||
|
||||
QString aspect = getAspect(mode.w, mode.h);
|
||||
QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h);
|
||||
|
||||
QString aspect = getAspect(mode.w, mode.h);
|
||||
if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) {
|
||||
resolution.append(tr("\t(Wide ") + aspect + ")");
|
||||
|
||||
|
@ -61,6 +61,9 @@ namespace
|
||||
std::string getAspect (int x, int y)
|
||||
{
|
||||
int gcd = std::gcd (x, y);
|
||||
if (gcd == 0)
|
||||
return std::string();
|
||||
|
||||
int xaspect = x / gcd;
|
||||
int yaspect = y / gcd;
|
||||
// special case: 8 : 5 is usually referred to as 16:10
|
||||
@ -249,8 +252,10 @@ namespace MWGui
|
||||
std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
|
||||
for (std::pair<int, int>& resolution : resolutions)
|
||||
{
|
||||
std::string str = MyGUI::utility::toString(resolution.first) + " x " + MyGUI::utility::toString(resolution.second)
|
||||
+ " (" + getAspect(resolution.first, resolution.second) + ")";
|
||||
std::string str = MyGUI::utility::toString(resolution.first) + " x " + MyGUI::utility::toString(resolution.second);
|
||||
std::string aspect = getAspect(resolution.first, resolution.second);
|
||||
if (!aspect.empty())
|
||||
str = str + " (" + aspect + ")";
|
||||
|
||||
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
||||
mResolutionList->addItem(str);
|
||||
|
Loading…
x
Reference in New Issue
Block a user