summary refs log tree commit diff
path: root/src/Utils.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-04-22 23:31:50 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-04-22 23:33:27 +0200
commit35601b6bef6165e254aa0becc38939f1122b0181 (patch)
tree2d29b5c70a8d958f3ce1c10517af5df871b116dc /src/Utils.cpp
parentAdd menu entry to show decrypted source (diff)
downloadnheko-35601b6bef6165e254aa0becc38939f1122b0181.tar.xz
Terminate user color calculation, when no solution can be found
fixes #172
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r--src/Utils.cpp6
1 files changed, 6 insertions, 0 deletions
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.