From ebb18ee3afe1ea81325b3490ef389a46eeab3b79 Mon Sep 17 00:00:00 2001 From: Christian Doczkal <20443222+chdoc@users.noreply.github.com> Date: Sun, 10 May 2026 09:54:51 +0200 Subject: [PATCH] Handle units without current soul in `Units::getFocusPenalty` --- docs/changelog.txt | 1 + library/modules/Units.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index cfff16e5a4..84b897421d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -66,6 +66,7 @@ Template for new versions: ## API - add flexible casting to ``enum_field`` to enable explicit casting to more types +- Handle units without current soul in ``Units::getFocusPenalty`` ## Lua diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index d8bfebdc97..707437ea34 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -2027,6 +2027,9 @@ int32_t Units::getFocusPenalty(df::unit* unit, need_type_set need_types) { CHECK_NULL_POINTER(unit); int max_penalty = INT_MAX; + if (!unit->status.current_soul) { + return max_penalty; + } auto& needs = unit->status.current_soul->personality.needs; for (auto const need : needs) { if (need_types.test(need->id)) {