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



commit a349a75efd53a0aa2d83534a3438b8e6bdc9b2c3
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".
    (cherry picked from commit 03a970ff9dfa49c31c7f1bb707cad0f0bf5484a3)

 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 18a68e3..39e00b1 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1209,6 +1209,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");
@@ -1711,9 +1716,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]