From 12525a25816ec207534d9c1cd41ed0558ca91692 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 10 Jan 2026 02:50:01 +0200
Subject: [PATCH 45/45] gtk: Fix flagless unit crash on action selection dialog

See RM #1867

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/action_dialog.c | 25 ++++++++++++++++++-------
 client/gui-gtk-4.0/action_dialog.c  | 25 ++++++++++++++++++-------
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/client/gui-gtk-3.22/action_dialog.c b/client/gui-gtk-3.22/action_dialog.c
index 3cd0532cbc..3e44979352 100644
--- a/client/gui-gtk-3.22/action_dialog.c
+++ b/client/gui-gtk-3.22/action_dialog.c
@@ -1470,13 +1470,24 @@ void popup_action_selection(struct unit *actor_unit,
              _("Your %s has arrived at %s.\nWhat is your command?"),
              unit_name_translation(actor_unit),
              city_name_get(target_city));
-  } else if (target_unit) {
-    astr_set(&text,
-             /* TRANS: Your Spy is ready to act against Roman Freight. */
-             _("Your %s is ready to act against %s %s."),
-             unit_name_translation(actor_unit),
-             nation_adjective_for_player(unit_owner(target_unit)),
-             unit_name_translation(target_unit));
+  } else if (target_unit != nullptr) {
+    struct player *owner = unit_owner(target_unit);
+
+    if (owner != nullptr) {
+      astr_set(&text,
+               /* TRANS: Your Spy is ready to act against Roman Freight. */
+               _("Your %s is ready to act against %s %s."),
+               unit_name_translation(actor_unit),
+               nation_adjective_for_player(unit_owner(target_unit)),
+               unit_name_translation(target_unit));
+    } else {
+      /* Flagless unit */
+      astr_set(&text,
+               /* TRANS: Your Spy is ready to act against Freight. */
+               _("Your %s is ready to act against %s."),
+               unit_name_translation(actor_unit),
+               unit_name_translation(target_unit));
+    }
   } else {
     fc_assert_msg(target_unit || target_city || target_tile,
                   "No target specified.");
diff --git a/client/gui-gtk-4.0/action_dialog.c b/client/gui-gtk-4.0/action_dialog.c
index af12630eac..3067db0981 100644
--- a/client/gui-gtk-4.0/action_dialog.c
+++ b/client/gui-gtk-4.0/action_dialog.c
@@ -1465,13 +1465,24 @@ void popup_action_selection(struct unit *actor_unit,
              _("Your %s has arrived at %s.\nWhat is your command?"),
              unit_name_translation(actor_unit),
              city_name_get(target_city));
-  } else if (target_unit) {
-    astr_set(&text,
-             /* TRANS: Your Spy is ready to act against Roman Freight. */
-             _("Your %s is ready to act against %s %s."),
-             unit_name_translation(actor_unit),
-             nation_adjective_for_player(unit_owner(target_unit)),
-             unit_name_translation(target_unit));
+  } else if (target_unit != nullptr) {
+    struct player *owner = unit_owner(target_unit);
+
+    if (owner != nullptr) {
+      astr_set(&text,
+               /* TRANS: Your Spy is ready to act against Roman Freight. */
+               _("Your %s is ready to act against %s %s."),
+               unit_name_translation(actor_unit),
+               nation_adjective_for_player(unit_owner(target_unit)),
+               unit_name_translation(target_unit));
+    } else {
+      /* Flagless unit */
+      astr_set(&text,
+               /* TRANS: Your Spy is ready to act against Freight. */
+               _("Your %s is ready to act against %s."),
+               unit_name_translation(actor_unit),
+               unit_name_translation(target_unit));
+    }
   } else {
     fc_assert_msg(target_unit || target_city || target_tile,
                   "No target specified.");
-- 
2.51.0

