Repository navigation
convert owned campaign mission strings to SCP_vm_unique_ptr - #7825
Draft
Goober5000 wants to merge 4 commits into
Draft
Goober5000 wants to merge 4 commits into
Goober5000 wants to merge 4 commits into
Conversation
Goober5000
force-pushed
the
refactor/campaign_mission_strings
branch
from
October 5, 2026 07:08
87a7671 to
cdc94d2
Compare
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
force-pushed
the
refactor/campaign_mission_strings
branch
from
October 7, 2026 19:36
cdc94d2 to
089bee5
Compare
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
force-pushed
the
refactor/campaign_mission_strings
branch
from
October 7, 2026 20:31
089bee5 to
68581f6
Compare
Goober5000
commented
Nov 18, 2026
Goober5000
left a comment
Contributor
Author
There was a problem hiding this comment.
Commenting to remind myself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Depends on #7824; in draft until that is merged.