From 24e3f79bde8ad4106eb9085cf3958840a397047e Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 31 Aug 2026 05:20:55 +0300
Subject: [PATCH 66/66] sdl: Fix crash when ruleset does not have roads for all
 gui_types

See RM #2192

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-sdl2/menu.c | 30 ++++++++++--------------------
 client/gui-sdl3/menu.c | 30 ++++++++++--------------------
 2 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/client/gui-sdl2/menu.c b/client/gui-sdl2/menu.c
index f1957b3376..ecb187ed16 100644
--- a/client/gui-sdl2/menu.c
+++ b/client/gui-sdl2/menu.c
@@ -1371,43 +1371,33 @@ void real_menus_update(void)
 
       {
         struct road_type *proad = road_by_gui_type(ROAD_GUI_ROAD);
-        bool road_conn_possible;
 
         if (proad != NULL) {
           struct extra_type *tgt;
 
           tgt = road_extra_get(proad);
 
-          road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
-        } else {
-          road_conn_possible = FALSE;
-        }
-
-        if (road_conn_possible) {
-          local_show(ID_UNIT_ORDER_CONNECT_ROAD);
-        } else {
-          local_hide(ID_UNIT_ORDER_CONNECT_ROAD);
+          if (can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt)) {
+            local_show(ID_UNIT_ORDER_CONNECT_ROAD);
+          } else {
+            local_hide(ID_UNIT_ORDER_CONNECT_ROAD);
+          }
         }
       }
 
       {
         struct road_type *proad = road_by_gui_type(ROAD_GUI_RAILROAD);
-        bool road_conn_possible;
 
         if (proad != NULL) {
           struct extra_type *tgt;
 
           tgt = road_extra_get(proad);
 
-          road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
-        } else {
-          road_conn_possible = FALSE;
-        }
-
-        if (road_conn_possible) {
-          local_show(ID_UNIT_ORDER_CONNECT_RAILROAD);
-        } else {
-          local_hide(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          if (can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt)) {
+            local_show(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          } else {
+            local_hide(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          }
         }
       }
 
diff --git a/client/gui-sdl3/menu.c b/client/gui-sdl3/menu.c
index 70e2149ca9..4c6670922b 100644
--- a/client/gui-sdl3/menu.c
+++ b/client/gui-sdl3/menu.c
@@ -1367,43 +1367,33 @@ void real_menus_update(void)
 
       {
         struct road_type *proad = road_by_gui_type(ROAD_GUI_ROAD);
-        bool road_conn_possible;
 
         if (proad != NULL) {
           struct extra_type *tgt;
 
           tgt = road_extra_get(proad);
 
-          road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
-        } else {
-          road_conn_possible = FALSE;
-        }
-
-        if (road_conn_possible) {
-          local_show(ID_UNIT_ORDER_CONNECT_ROAD);
-        } else {
-          local_hide(ID_UNIT_ORDER_CONNECT_ROAD);
+          if (can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt)) {
+            local_show(ID_UNIT_ORDER_CONNECT_ROAD);
+          } else {
+            local_hide(ID_UNIT_ORDER_CONNECT_ROAD);
+          }
         }
       }
 
       {
         struct road_type *proad = road_by_gui_type(ROAD_GUI_RAILROAD);
-        bool road_conn_possible;
 
         if (proad != NULL) {
           struct extra_type *tgt;
 
           tgt = road_extra_get(proad);
 
-          road_conn_possible = can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt);
-        } else {
-          road_conn_possible = FALSE;
-        }
-
-        if (road_conn_possible) {
-          local_show(ID_UNIT_ORDER_CONNECT_RAILROAD);
-        } else {
-          local_hide(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          if (can_unit_do_connect(punit, ACTIVITY_GEN_ROAD, tgt)) {
+            local_show(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          } else {
+            local_hide(ID_UNIT_ORDER_CONNECT_RAILROAD);
+          }
         }
       }
 
-- 
2.53.0

