Repository navigation
Fix subsystem data being lost or mismatched for ship classes and modular tables - #7909
Goober5000 wants to merge 8 commits into
Conversation
17549e5 to
5aade26
Compare
dustinspace217
left a comment
There was a problem hiding this comment.
The crash, dangling-pointer and flag fixes check out against master. A few things:
- Engine wash now reads
wash_sip->subsystems[bank->subsys_num], which is the engine's position in the class that loaded the model. Master took the wash from that class's engine found by name, so a reordered class still washed; now it can read another subsystem's empty setting. Could the bank resolve the engine by name instead? Matching onsubobj_numwon't work for$enginelargespecial points, since those are -1. ship_copy_subsystem_fixupstill stops at the first class whosesubsystems[0]is linked. With name matching, a partly matching class can now be that source, so a third class can miss a subsystem the loading class has. Keep looking while any destination subsystem is unlinked?- The "keep this up to date" comment on the preset lists would also cover Stealth and the legacy
+untargetable-style tags, which are rightly left out since$Flagssets them too. Maybe "flags that$Flagsitself cannot set"? - Worth a line in the description that the second class now gets paths,
$pbankspin, POF FOVs and its own wash, since today that depends on which class loads the model (even the tech room can pick it).
Optional: a table-only test for the $Flags fix. Heads-up: #7835 resets Ships_inited in ship_close, so the fixture's manual resets can go once both land.
5aade26 to
5673cf5
Compare
Nothing reset the IFF module's state, so a second iff_init() in the same process failed on duplicate IFF names. IffAccessibilityTest (scp-fs2open#7856) calls iff_init(), which broke any later test that also needed IFFs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A modular table that repeats $Flags: without +noreplace replaced the whole flagset, dropping flags that are set by other table entries: - subsystem $Flags: dropped the turret FOV override flags set by $Turret Barrel FOV:, $Turret Base FOV: and $Maximum Barrel Elevation:, so the POF values silently replaced the tabled ones - ship $Flags: dropped Has_awacs and Allow_landings, which are set while parsing subsystems Both now keep a list of preset flags, following the preset_wi_flag_defs pattern used for weapons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POF subsystem properties are only read for the first ship class that loads a model; other classes receive them through model_copy_subsystems, which missed several fields: - stepped_rotation / stepped_translation were not copied even though their flags were, causing a null dereference (crash) for $stepped submodels - turret_fov was copied over the destination's $Turret Barrel FOV:, or leaked the source class's tabled value into the destination - turret_base_fov and turret_max_fov were not copied at all - path_num and weapon_rotation_pbank were not copied The POF FOV values are now kept in separate pof_ fields so that each class can apply its own ships.tbl overrides on top of them, in either copy direction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The thruster bank stored the $Engine Wash: pointer of the first ship class that loaded the model, so other classes sharing the model used that class's wash and ignored their own. The huge-ship default wash was also written into the shared bank at runtime, after which non-huge classes sharing the model picked it up too. The bank now stores the index of its engine subsystem, and the wash is resolved from the ship's own class each time. The index belongs to the class that loaded the model, so it is bounds-checked against the ship's class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some mods share a model between ship classes whose subsystem lists differ, for example when a modular table adds subsystems to only one of them. The model stores subsystem indices for the class that loaded it, and the copy between classes assumed identical lists (checked only by a debug Assert), so such mods could read past the end of a class's subsystems. - model_copy_subsystems takes both counts and walks the destination's subsystems, matching them by name; an unmatched one stays unlinked and is reported when a ship of that class is created, as before - skip classes with no subsystems when looking for one to copy from - bounds-check the model's subsystem indices in ship_get_subsys_for_submodel and the engine glow check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A POF's subsystem data is read only for the first ship class that loads the model, and the model stores indices into that class's subsystem list. When classes sharing the model list different subsystems, or the same ones in a different order, hits and engine effects can be applied to the wrong subsystem, and a ship can fail to load if its class has subsystems the loading class lacks. Check this once after all ship tables are parsed and raise a Warning naming both classes, the model, and the first difference. A sweep of existing mods found such mismatches in several of them, mostly from modular tables that add subsystems to only one of the classes, so this is a Warning rather than an Error. Add unit tests for identical, reordered, extra and missing subsystems. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Subsystems stored a pointer into Engine_wash_info, but a modular ship table parsed later can add new engine washes, and the resulting push_back can reallocate the vector, leaving every previously stored pointer dangling. Store an index instead and resolve it when the wash is used. Also drop Num_engine_wash_types in favor of the vector's size, and clear the vector when ships.tbl is reparsed so the two cannot disagree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A modular table replaces a ship's and a subsystem's $Flags: without +noreplace. The test checks that the replacement takes effect and that Has_display_name, Afterburner, Has_awacs, Allow_landings and the turret FOV override flags survive it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5673cf5 to
46150f5
Compare
|
@dustinspace217 Claude's reply... Thanks for the careful review! Here's where each point landed:
Optional test: added as #7835: the fixture's manual Every commit builds cleanly in Debug (Freespace2, FRED2, qtfred and unittests), and the full unit suite passes at the tip. |
Now depends on #8077; in draft until that PR is merged.
Summary
This fixes several related problems where subsystem data set by ships.tbl or the POF was silently lost, or applied to the wrong ship class. Some of them could crash the game.
1. Flags set outside
$Flags:were dropped by modular tablesA .tbm that repeats
$Flags:without+noreplacereplaced the whole flag set. That also cleared flags set by other table entries:$Flags:dropped the internalTurret_*_fov_overriddenflags set by$Turret Barrel FOV:,$Turret Base FOV:and$Maximum Barrel Elevation:. The POF values then overwrote the table values when the model was read.$Flags:droppedHas_awacsandAllow_landings, which are set while subsystems are parsed. For example, a ship's AWACS stopped working.Both now keep a list of these preset flags, using the same pattern as
preset_wi_flag_defsin weapons.cpp. The ship-level list replaces the existing hand-written save/restore ofAfterburner,Draw_weapon_modelsandHas_display_name.2. Ship classes sharing a POF lost POF subsystem data
POF subsystem properties are only parsed for the first ship class that loads a model. Other classes get them through
model_copy_subsystems, which missed several fields:stepped_rotation/stepped_translation: theStepped_*flags were copied but the data they point to wasn't. Any$steppedsubmodel on the second class then dereferenced a null pointer every frame and crashed the game.turret_fov: copied regardless of$Turret Barrel FOV:. That overwrote the destination class's own override, or passed the source class's table value on to a destination that had none.turret_base_fov/turret_max_fov: not copied at all, so the POF's$base_fovand$max_fovlimits were lost.path_num: not copied, so AI subsystem attack paths and LuaModelPathdidn't work for the second class.weapon_rotation_pbank: not copied, so$pbankbarrels didn't spin while primaries were unlinked.The POF FOV values are now stored in separate
pof_turret_*fields. Each class applies its own ships.tbl overrides on top of them, which gives the right result in whichever direction the copy runs.Before this change, which of the classes sharing a model got this data depended on which class loaded the model first, and that can be decided by something as incidental as the tech room or ship selection. Every class sharing the model now gets its paths,
$pbankspin, POF FOVs and (see below) its own engine wash, regardless of load order.3. Engine wash came from the class that loaded the model
Each thruster bank stored the
$Engine Wash:of the class that loaded the model, so other classes sharing the model ignored their own. The huge-ship default wash was also written into the shared bank at runtime, after which non-huge classes sharing the model got it too. The bank now stores its engine subsystem's index, bounds-checked against each class, and the wash is looked up in the ship's own class.4. Ship classes sharing a POF with different subsystem lists
The model stores subsystem indices for the class that loaded it, and the copy between classes assumed identical subsystem lists. That was checked only by a debug
Assert, so release builds could read past the end of a class's subsystem list.model_copy_subsystemsnow takes both counts and matches subsystems by name. A destination subsystem with no match stays unlinked and is reported when a ship of that class is loaded, as before.ship_get_subsys_for_submodeland the engine-glow check.Known limitations, both pre-existing and only reported by the new Warning:
5. Engine wash pointers could dangle after a modular table
Subsystems stored
$Engine Wash:as a pointer intoEngine_wash_info. A modular ship table parsed later can add new engine washes, and the resultingpush_backcan reallocate the vector, leaving every pointer stored by earlier tables dangling. Subsystems now store an index, which is resolved when the wash is used.Num_engine_wash_typesis replaced by the vector's size, and the vector is now cleared when ships.tbl is reparsed. Before, only the counter was reset, so the two could disagree if ship tables were parsed more than once in a process, as in the unit tests.Testing
In-game, with retail data and a Debug build. GTC Fenris/Leviathan share
cruiser01.pof, and SC Lilith/Cain sharecruiser03.pof.cruiser01.pofwas edited to add$base_fov/$max_fovto the main turret and$steppedto the radar dish.$Flags:without+noreplace.Results:
$Flags:replacement.$Flags:is replaced.Engine wash, in-game, with retail data and a Debug build. A test .tbm gave the Fenris
Default100, the LeviathanDefault1500and the LilithDefault1000, and left the Cain without one.cruiser03.pofhas no$engine_subsystem=link, and cruisers don't get the huge-ship default.Table parsing across existing mods. A Debug build was run headlessly (
-noninteractive, exiting right aftergame_init()) against retail data and a curated subset of 84 mods: standalone mods using mod.ini, and Knossos-installed mods and total conversions with their dependencies resolved from mod.json.SD Lucifer/SD Lucifer#scanhave 32 subsystems,SD Lucifer#scancapitalhas 30 (capital02-shielded.pof). FSPort defines all three identically. MediaVPs 3.6.12 and older FSPort-MediaVPs then add turrets to some of them, but never to#scancapital. Mods using FSPort-MediaVPs 4.7.2 with MVPS 4.7.3 are unaffected.GVD Typhon(22) vsMIND Ra(34) onTyphon.pof.#Camera(0) vsAstLayer(3) onblip2.pof.Supply WyvernvsWyvernlist their subsystems in a different order.PVD TyphonvsPVD Typhon Refitlist their subsystems in a different order.GTSG Mjolnir#homeproduced the expected Warning.Unit tests were added for the shared-model check, covering identical, reordered, extra and missing subsystem lists. The full suite passes.
Builds: Freespace2 and FRED2 build cleanly in Debug at every commit. All unit tests pass (one is skipped by the suite).
🤖 Generated with Claude Code