From 35601b6bef6165e254aa0becc38939f1122b0181 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 22 Apr 2020 23:31:50 +0200 Subject: [PATCH] Terminate user color calculation, when no solution can be found fixes #172 --- CHANGELOG.md | 1 + src/Utils.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd4363c..93a4d9d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Fix crash when trying to maximize image, that wasn't downloaded yet. - Fix Binding restorMode flooding logs on Qt 5.14.2+ - Fix with some qml styles hidden menu items leave empty space +- Fix hangs when generating colors with some system theme color schemes (#172) ## [0.7.0] -- 2020-04-19 diff --git a/src/Utils.cpp b/src/Utils.cpp index 33b75894..62a1a3c8 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -540,6 +540,7 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou // If the contrast doesn't meet our criteria, // try again and again until they do by modifying first // the lightness and then the saturation of the color. + int iterationCount = 9; while (contrast < 5) { // if our lightness is at it's bounds, try changing // saturation instead. @@ -586,6 +587,11 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou } } } + + // don't loop forever, just give up at some point! + // Someone smart may find a better solution + if (--iterationCount < 0) + break; } // get the hex value of the generated color.