Skip to content

Fix ship_page_in discarding valid subsystem links when ship classes share a POF - #8068

Open
wookieejedi wants to merge 1 commit into
scp-fs2open:masterfrom
wookieejedi:fix-shippage-bug-withbriefings
Open

wookieejedi wants to merge 1 commit into
scp-fs2open:masterfrom
wookieejedi:fix-shippage-bug-withbriefings

Conversation

@wookieejedi

Copy link
Copy Markdown
Member

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.

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.
@wookieejedi wookieejedi added the fix A fix for bugs, not-a-bugs, and/or regressions. label Nov 17, 2026

@dustinspace217 dustinspace217 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right to me. On master, when an earlier class that shares the POF already has model_num set (from the briefing closeup, ship select, the tech room or Lua) and the current class is linked, ship_page_in clears the current class's links and ship_copy_subsystem_fixup() then has no linked class to copy from. Checking whether the current class's subsystems already point at this model id avoids that, and classes that don't share a POF, or aren't linked yet, take the same path as before.

I couldn't get the error to happen on master, so I haven't seen this fail or pass in the game. I tried two setups with Debug builds of master (f0d45f6) and master with this PR, retail FS2 plus MediaVPs 5.0.3, and SM1-04, which has an SC Cain (it shares cruiser03.pof with the SC Lilith): loading the Lilith's model through tb.ShipClasses['SC Lilith']:isModelLoaded(true) at the briefing, which turned out to be after the mission's page-in, and loading it while the game was starting the mission, before SM1-04's page-in. Neither hit the error on master. If you have steps that hit it, I'm happy to run them on both builds.

@Goober5000

Copy link
Copy Markdown
Contributor

Pretty sure this is a duplicate of #7909

@wookieejedi

Copy link
Copy Markdown
Member Author

That PR lists point 4 part 2 bullet point 2 as still an issue, which is the main thing this pr fixes 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants