Skip to content

convert owned campaign mission strings to SCP_vm_unique_ptr - #7825

Draft
Goober5000 wants to merge 4 commits into
scp-fs2open:masterfrom
Goober5000:refactor/campaign_mission_strings
Draft

Goober5000 wants to merge 4 commits into
scp-fs2open:masterfrom
Goober5000:refactor/campaign_mission_strings

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

The five vm_strdup'd strings in cmission (name, notes, and the three mission-branch strings) are now SCP_vm_unique_ptr, which makes cmission move-only and removes mission_campaign_free_mission_strings. nullptr still means absent, and each buffer stays put when its owner moves, so raw pointers held by sim_room_lines remain valid.

This fixes several ownership bugs:

  • FRED2's campaign tree links shared the cmission branch strings, then free()d them when edited, so mission_campaign_clear freed them a second time. The links now hold their own copies.
  • FRED2 and qtFRED allocated these strings with strdup but released them with vm_free.
  • qtFRED's mission list sync freed only the name of removed missions, leaking the other four strings.
  • Multiplayer clients overwrote a mission name on debrief without freeing the old one.

Depends on #7824; in draft until that is merged.

@Goober5000 Goober5000 added this to the Release 27.0 milestone Oct 5, 2026
@Goober5000 Goober5000 added fix A fix for bugs, not-a-bugs, and/or regressions. refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability labels Oct 5, 2026
@Goober5000
Goober5000 force-pushed the refactor/campaign_mission_strings branch from 87a7671 to cdc94d2 Compare October 5, 2026 07:08
Campaigns were limited to 100 missions by a fixed-size array in the
campaign struct, and the campaign parser did not check that limit, so a
campaign file with more missions overflowed the array into the vectors
that follow it.  Campaign.missions is now an SCP_vector sized by the
parser, and the separate num_missions count is replaced by the vector's
size.  cmission members now have default initializers so that resized
entries start out valid.

The other arrays sized by MAX_CAMPAIGN_MISSIONS are vectors as well: the
mission name lists in the mission load menu and the ready room.  In FRED2,
the campaign tree's Sorted, Elements, Level_counts, and Links arrays are
vectors too, which removes the MAX_LEVELS and MAX_CAMPAIGN_TREE_LINKS
limits and the separate Total_links count.  Removing a mission from the
tree now pops the vacated last slot.

The multiplayer client sizes its mission list from the count the server
sends.  Multiplayer campaigns are still limited to 255 missions, since
the protocol sends the count as a ubyte.

When reading a campaign save file, data for a stored mission index that
is out of range is now discarded, where it was previously written into
the array without a check.  The Lua campaign mission accessors, the loop
brief stage handle, the debriefing persona lookup, and the main hall
lookups also check the index against the mission list, and the main hall
falls back to its defaults when the campaign has no missions.

Since a save file's mission data is stored by index, it only applies to
the campaign it was saved from.  The barracks and pilot selection screens
can load a pilot's save file while a different campaign is loaded, so
mission data from a save file for another campaign is now discarded, and
saving is skipped until a matching save file is loaded or the save data
is cleared, so that the mixed data is not written to the campaign's save
file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Goober5000
Goober5000 force-pushed the refactor/campaign_mission_strings branch from cdc94d2 to 089bee5 Compare October 7, 2026 19:36
Goober5000 and others added 3 commits October 7, 2026 16:15
The sim room listed standalone and campaign missions through fixed
arrays of 1024 entries.  These arrays are now vectors, and the
separate Num_standalone_missions and Num_campaign_missions counts
are replaced by the vectors' sizes.

mission_campaign_get_mission_list now appends to an SCP_vector of
strings instead of filling a caller-sized char* array.

The sim room's mission name vectors now own their strings through
SCP_vm_unique_ptr and are cleared unconditionally.  Previously they
were freed only when the *_inited flags were set, which leaked the
names when a listing was cancelled partway and in
api_sim_room_build_mission_list, which reset the flags before freeing.

The standalone and campaign mission flag arrays are removed; they
were written but never read, back to the original source release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The campaign list (Campaign_names, Campaign_file_names, and
Campaign_descs) was held in fixed arrays of 128 owned char* strings.
These are now SCP_vector<SCP_string>, filled through the SCP_vector
overload of cf_get_file_list, and Num_campaigns is replaced by the
vectors' size.  An empty name or description now means absent.

mission_campaign_get_info returns the description and first mission
through SCP_string out-parameters, which also fixes a leak of the
description when parsing failed partway.

pilot_set_start_campaign no longer writes into the global
Campaign_names with a counter that was never reset.  It now checks
the default campaign first, and only if that is missing or not a
valid single-player campaign does it parse the rest and pick the one
whose title sorts first, replacing the file list filter, its static
name list, and the shell sort.  The debug mission load menu builds
its campaign filter list from vectors, which also lines the names up
with the Campaign_filter_index-2 lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five vm_strdup'd strings in cmission (name, notes, and the three
mission-branch strings) are now SCP_vm_unique_ptr<char>, which makes
cmission move-only and removes mission_campaign_free_mission_strings.
nullptr still means absent, and each buffer stays put when its owner
moves, so raw pointers held by sim_room_lines remain valid.

This fixes several ownership bugs:
- FRED2's campaign tree links shared the cmission branch strings, then
  free()d them when edited, so mission_campaign_clear freed them a
  second time.  The links now hold their own copies.
- FRED2 and qtFRED allocated these strings with strdup but released
  them with vm_free.
- qtFRED's mission list sync freed only the name of removed missions,
  leaking the other four strings.
- Multiplayer clients overwrote a mission name on debrief without
  freeing the old one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Commenting to remind myself

Comment thread code/mission/missionload.cpp Resolved
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. refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant