[gnome-2048] Fix crash due to not available colors
- From: Juan R. Garcia Blanco <juanrgar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-2048] Fix crash due to not available colors
- Date: Sun, 15 Feb 2015 21:32:04 +0000 (UTC)
commit 445d6769678a6ea01c4d1395812d586a782d39f7
Author: Juan R. GarcĂa Blanco <juanrgar gmail com>
Date: Sun Feb 15 22:22:07 2015 +0100
Fix crash due to not available colors
Tiles up to 2048 are assigned colors, while tiles greater than that are
not. The program crashed when such a tile needed to be displayed.
A very simple algorithm has been added to deterministically generate
colors based on the tile value and a pre-defined set of colors.
https://bugzilla.gnome.org/show_bug.cgi?id=743119
src/view.vala | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/src/view.vala b/src/view.vala
index 3d0428d..aef124e 100644
--- a/src/view.vala
+++ b/src/view.vala
@@ -177,6 +177,23 @@ public class ColorPalette : GLib.Object
public Clutter.Color pick_color (uint val)
{
- return _palette.get (val);
+ Clutter.Color color;
+
+ if (_palette.has_key (val)) {
+ color = _palette.get (val);
+ } else {
+ uint norm_val;
+ uint8 sbits;
+
+ norm_val = val / 2048;
+ color = _palette.get (norm_val);
+
+ sbits = (uint8)(val % 7);
+ color.red <<= sbits;
+ color.green <<= sbits;
+ color.blue <<= sbits;
+ }
+
+ return color;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]