From 35a9289b2c99697f3e07af585b31e83a4084c24f Mon Sep 17 00:00:00 2001 From: wookieejedi Date: Tue, 17 Nov 2026 09:56:17 -0500 Subject: [PATCH] Update ship.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug When ship classes share a POF, ship_page_in could clear a class’s valid subsystem links and then fail to restore them. That raised one Error per subsystem: After ship_copy_subsystem_fixup in ship_page_in, ship ‘X’ does not have subsystem ‘Y’ linked into the model file ... (subsystem model is ‘NULL’) It only happened partway through a session, depending on what happened in earlier missions. Restarting the game cleared it. Cause If the model is already loaded, model_load(pof, sip) sets sip->model_num and returns without linking sip’s subsystems. UI screens hit this path: the briefing closeup, ship select, the techroom and the Lua shipclass render functions. Afterwards a class can have a valid model_num while its subsystems still point to -1. ship_page_in takes the first Ship_info entry with the same POF and model_num > -1 as the class that loaded the model. If that entry isn’t the current class, it sets the current class’s subsystem model_nums to -1 and calls ship_copy_subsystem_fixup(). If the entry it found was one of the classes from step 1, and the current class was the only one actually linked, the fixup finds nothing to copy from. It never copies a class from itself, and the current class’s links have just been cleared. Fix Before using the class it found, ship_page_in now checks whether the current class’s subsystems already point to this exact model id. If they do, it treats the current class as the one that loaded the model and takes the existing “no fixup needed” path. Model ids include a per-load signature, so a match means the links really come from this load. The check runs before the loop that rewrites mismatched subsystem model_nums, so that loop can’t make a stale link look valid. Classes with no subsystems or with unlinked subsystems behave exactly as before. The early return in model_load() still doesn’t link subsystems. It just can no longer cause a correctly linked class to lose its links. --- code/ship/ship.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/code/ship/ship.cpp b/code/ship/ship.cpp index b4e6907e499..546790fc858 100644 --- a/code/ship/ship.cpp +++ b/code/ship/ship.cpp @@ -19022,7 +19022,20 @@ void ship_page_in() // Model already loaded model_previously_loaded = it->model_num; - if ((sip->n_subsystems > 0) && (sip->subsystems[0].model_num > -1)) { + // The class found above may only have model_num set (e.g. by a briefing closeup) without + // linked subsystems. If this class is already linked to this model, keep its links rather + // than clearing them and relying on ship_copy_subsystem_fixup() to find another source. + bool sip_already_linked = (sip->n_subsystems > 0); + for (k = 0; k < sip->n_subsystems; k++) { + if (sip->subsystems[k].model_num != model_previously_loaded) { + sip_already_linked = false; + break; + } + } + + if (sip_already_linked) { + ship_previously_loaded = i; + } else if ((sip->n_subsystems > 0) && (sip->subsystems[0].model_num > -1)) { ship_previously_loaded = (int)std::distance(Ship_info.begin(), it); // It is possible in some cases for sip->model_num to change, and for subsystems->model_num