[gnome-chess] Behave properly when no engines are installed



commit 1988dc80747963fdbb901724090dc033119ff55e
Author: Michael Catanzaro <mike catanzaro gmail com>
Date:   Wed May 15 20:23:36 2013 -0500

    Behave properly when no engines are installed
    
    ai_profiles only contains the list of installed engines, so this can
    reasonably be expected to be empty on distros which do not require a
    chess engine (such as Arch). Make sure it's not so we don't segfault.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700330
    
    If no engines are installed, the opponent combo box will be blank, which
    is confusing. Moreover the game will break completely in this case if
    you set to play Black. So actually set the opponent to "human".

 src/gnome-chess.vala |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 78901aa..1b91663 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1208,6 +1208,11 @@ public class Application : Gtk.Application
             if (p.name == opponent_name || (opponent_name == "" && ai_combo.get_active () == -1))
                 ai_combo.set_active_iter (iter);
         }
+        if (ai_combo.get_active () == -1)
+        {
+            ai_combo.set_active (0);
+            settings.set_string ("opponent", "human");
+        }
         settings.bind ("show-history", ai_combo, "visible", SettingsBindFlags.SET);
 
         var difficulty_combo = (Gtk.ComboBox) preferences_builder.get_object ("difficulty_combo");
@@ -1710,9 +1715,13 @@ public class Application : Gtk.Application
         if (duration > 0)
             pgn_game.time_control = "%d".printf (duration);
         var engine_name = settings.get_string ("opponent");
-        /* explicitly specify engine name in saved game */
         if (engine_name == "")
-            engine_name = ai_profiles.data.name;
+        {
+            if (ai_profiles != null)
+                engine_name = ai_profiles.data.name;
+            else
+                engine_name = "human";
+        }
         var engine_level = settings.get_string ("difficulty");
         if (engine_name != null && engine_name != "human")
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]