Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12236: Ship pathfinder causes crash when ship is already at destination #12238

Merged

Conversation

Kuhnovic
Copy link
Contributor

@Kuhnovic Kuhnovic commented Mar 8, 2024

Motivation / Problem

Fixes #12236

Description

A call to chooseShipTrack is pointless when already at the destination, but it can happen in certain edge cases. Whether these situations should occur in the first place is debatable, and #11862 is an example of such a situation. However, the PF should be able to deal with such strange requests. It certainly shouldn't crash.

I opted for just returning a single random trackdir that can be reached, or INVALID_DIR otherwise, which in turn causes the ship to turn around. This should hopefully get nudge the ship out of the current situation and find a correct path ont he next PF call.

I also decided to not report the ship as lost (by not setting path_found = false), since the destination is technically found and the ship is not really lost. It's a strange situation so the solution is maybe a little strange as well.

Limitations

While this will make the PF more robust, the issue causing these situations is not fixed.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@Kuhnovic Kuhnovic merged commit 08ff1ab into OpenTTD:master Mar 8, 2024
19 checks passed
@Kuhnovic Kuhnovic deleted the ship_pf_fix_zero_path_length_crash branch March 9, 2024 18:23
@Kuhnovic Kuhnovic added the backport requested This PR should be backport to current release (RC / stable) label Mar 9, 2024
Kuhnovic added a commit to Kuhnovic/OpenTTD that referenced this pull request Mar 9, 2024
michicc pushed a commit to Kuhnovic/OpenTTD that referenced this pull request Mar 9, 2024
@Kuhnovic Kuhnovic added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Crash]: during pathfinding with ships
2 participants