Skip to content

Fix crash in ai_manage_bay_doors from stale destroyed parent ship#7564

Merged
The-E merged 1 commit into
scp-fs2open:masterfrom
The-E:fix/ai-manage-bay-doors-stale-parent
Jul 5, 2026
Merged

Fix crash in ai_manage_bay_doors from stale destroyed parent ship#7564
The-E merged 1 commit into
scp-fs2open:masterfrom
The-E:fix/ai-manage-bay-doors-stale-parent

Conversation

@The-E

@The-E The-E commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Found via debugger: ai_manage_bay_doors (code/ai/aicode.cpp) can assert/crash calling model_get_instance(-1) when a departing fighter's bay-door "parent" carrier was already destroyed earlier in the mission.
  • Root cause: the carrier's Ships[] entry retains stale bay door state (bay_doors_status, bay_doors_wanting_open) even after its object and model instance have been freed (objnum == -1, model_instance_num == -1). The existing guard only checked that a parent shipnum was assigned, not that the parent was still alive.
  • Fix: after resolving parent_ship, return early if parent_ship->objnum < 0 || parent_ship->model_instance_num < 0, mirroring the validity checks used elsewhere in the codebase (e.g. shiphit.cpp, object.cpp) before touching a ship's model instance.

Test plan

  • Reproduce original crash scenario (fighter departing/being destroyed after its carrier was already destroyed) and confirm no crash/assert occurs with the fix.
  • Sanity-check normal bay door open/close behavior (fighter launching/recovering to a live carrier) is unaffected.

If the carrier a fighter launched from was destroyed earlier in the
mission, its Ships[] entry retains stale bay door state while its
object and model instance are already freed (objnum/model_instance_num
== -1). When the fighter later departs, ai_manage_bay_doors would still
try to animate the dead carrier's bay doors, calling
model_get_instance(-1) and asserting/crashing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@The-E The-E merged commit 2cb9227 into scp-fs2open:master Jul 5, 2026
18 checks passed
@The-E The-E deleted the fix/ai-manage-bay-doors-stale-parent branch July 5, 2026 11:43
@wookieejedi wookieejedi added the Point Release Candidate An already merged bugfix that may be merged into a previous stable version label Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Point Release Candidate An already merged bugfix that may be merged into a previous stable version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants