Skip to content

Fix crash when asking for defenders of harbor with waiting attackers#1913

Merged
Flamefire merged 6 commits into
Return-To-The-Roots:masterfrom
Flamefire:soldier-cancel
Apr 22, 2026
Merged

Fix crash when asking for defenders of harbor with waiting attackers#1913
Flamefire merged 6 commits into
Return-To-The-Roots:masterfrom
Flamefire:soldier-cancel

Conversation

@Flamefire

@Flamefire Flamefire commented Apr 19, 2026

Copy link
Copy Markdown
Member

What happened:

  • Sea attack starts
  • Attacker arrives in start harbor and waits for ship
  • target is destroyed, attacker prepares to leave to go back home
  • harbor is attacked
  • "active" soldiers that want to leave are stopped, including this attacker
  • code wrongly considers this as belonging to this building

This was indeed introduced by #1910
Prior to that such a soldier would be ignored here.

The result is:

  • Harbor is attacked
  • Soldier gets notified its goal has already been destroyed
  • He goes home
  • Comes out and ignores the ongoing fight, YOLO

The idea is to potentially use those for defense.
However e.g. harbors might contain soldiers that belong to another
building and are about to leave.

Don't consider those as this complicates the logic too much and just revert to this behavior.

It fixes the crash which is prior to that caught by an assertion: The soldier is not in troop_on_mission.
Fixes #1912

Also fix an assertion failure that detected a mismatch in expected armors: There could be more armored soldiers than soldiers (logic is we have n of m soldiers with armor)
This is detected by continuing the provided savegame.

To avoid similar issues I deduplicated code handling the warehouse inventory: Boat-carrier, soldier and others have to be handled consistently

The idea is to potentially use those for defense.
However e.g. harbors might contain soldiers that belong to another
building and are about to leave.

Don't consider those as this complicates the logic too much.

Currently it crashed because adding "active" soldiers is assumed to be
either the defender or a soldier on a mission from this building.
Other soldiers will get lost in the accounting of their home building.

Fixes Return-To-The-Roots#1912
It combines handling of armor and boat carriers.
@Flamefire Flamefire requested a review from Flow86 April 19, 2026 19:31
Comment thread libs/s25main/buildings/nobBaseMilitary.cpp
Comment thread libs/s25main/figures/nofActiveSoldier.cpp
Comment thread libs/s25main/figures/nofSoldier.cpp
Comment thread libs/s25main/figures/nofSoldier.h Outdated
Replaced by `GetHome` & `GetGoal`
@Flamefire Flamefire merged commit 45e8bc0 into Return-To-The-Roots:master Apr 22, 2026
20 checks passed
@Flamefire Flamefire deleted the soldier-cancel branch April 22, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random crashes since 09-04-2026 release (?on multiplayer with harbours?)

2 participants