Skip to content

P3: Fix more data-loss bugs in qtFRED, and a variable rename crash in both editors - #8029

Open
dustinspace217 wants to merge 11 commits into
scp-fs2open:masterfrom
dustinspace217:fix/editor-batch2
Open

dustinspace217 wants to merge 11 commits into
scp-fs2open:masterfrom
dustinspace217:fix/editor-batch2

Conversation

@dustinspace217

@dustinspace217 dustinspace217 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What?

Small editor fixes, one commit each. The first three were in this PR when it opened; the rest came out of the same comparison and touch the same files.

  • Fiction viewer: clearing the story file deleted every fiction stage in the mission, not only the first one, which is the one the dialog edits.
  • Variables: a variable changed from number to string was still saved as a number. The new type is saved now, and OK refuses a type change for a variable the team loadout uses.
  • Toolbar Rename: it accepted another ship's name and a name too long for the name field (an assert in Debug). It was also offered for a wing member, and renaming one left the wing with a ship the pre-save check reports.
  • Ship editor: clicking into the Ship Name box and leaving it without typing reset a custom display name, and the next save lost it. A refused rename did the same.
  • Wing editor: the same thing for a wing's display name. Tabbing through the name box renamed the wing to its own name, which resets the display name.
  • Variables: when two variables traded names in one OK, both ended up with the same value and flags. Names that differ only in case were also mixed up: with "Cancer" and "cancer", an untouched OK saved one value under both names, and deleting "cancer" deleted nothing.
  • Variables, both editors: a rename did not reach everything that refers to the variable by name. In both editors the team loadout kept the old name, and the next save (in my FRED test, the autosave when the events editor closed) hit an assert in Debug builds and read before the start of the variable list in Release. qtFRED's rename also missed events, which then saved the variable as undefined. FRED's rename reached only the sexp tree it was started from, so a rename from a wing's cue left the events on the old name and saving stopped on "Couldn't find variable" warnings.

Why?

Each of these loses or changes a mission designer's work, most of them with no message at the time. The rename one also takes FRED down in Debug builds, with whatever was not saved.

How?

  • The fiction viewer removes the first stage only, as FRED does. Rename uses the ship editor's name check, and a wing member no longer gets the button.
  • The ship and wing editors reset a display name only when the name really changed, as FRED does.
  • The variables OK finds every variable by its exact old name before it renames any, then renames sexp references in one pass over the sexp nodes, the same way container renames already reach events.
  • That reference update, sexp nodes and loadout together, is a new function beside the loadout counter in the shared editor code, and both editors call it.

Testing?

  • Each bug was reproduced first on master in qtFRED (Debug, Linux), then rechecked on a build of this branch. Results were read from the saved mission file, not from the dialog.
  • FRED, built with MSVC on Windows 11, before and after: renaming a ship pool count variable from the events editor (assert, then the new name saved), and renaming an event's variable from a wing's departure cue (warnings and no save, then the event saved with the new name). Not run in FRED: a case-only rename, and class or weapon variables; they go through the same code. The fiction viewer case was run in FRED 26.2.0. For the other FRED claims I read the source and did not run it.
  • MediaVPs 5.0.2 and a test mod holding copies of SM1-01 with the fields under test added by hand: fiction stages, a ship and a wing with display names, and variables with network and persistence flags, one used in an event and one as a ship pool count.
  • Debug and Release build without warnings on Linux, and the unit tests pass. No automated tests: these dialogs have no test target.

Anything Else?

  • An events editor that is open during a rename keeps its own copy and writes the old name back when it is closed with OK. Container renames behave the same way. I left that alone because the fix is a choice between closing open editors and reloading them.
  • Backport the QtFRED Undo System #8017 rewrites the toolbar Rename function and the ship name handler, and wraps the variables dialog in an undo step. Its undo restores the variable list but not renamed references. I can rebase after it or drop commits here, whichever is easier.
  • Left alone: qtFRED still lets you change the type of a variable that events use, or delete one the loadout uses. FRED refuses those. (The first version of this text said FRED also refuses renaming one the loadout uses. It does not; that case is the crash fixed above.)
  • The wing arrival distance fix that was here is now covered by Various fixes for qtFRED #8030, so I took it out to avoid a duplicate.
  • I wrote this with help from Claude Code.

… changes

Changing a wing's arrival target set its arrival distance to 0 whenever the distance was larger than the new target's minimum, because the comparison was the wrong way round. The box went on showing the minimum, and the pre-save check then reported that the distance must be greater than 0. A distance below the minimum was left as it was. The distance is now raised to the minimum only when it is below it, as the arrival location handler a few lines up already does.
…e first stage

The dialog edits the first fiction viewer stage, but a mission file can hold several. Clearing the story file and pressing OK deleted all of them. Only the first stage is removed now.
Changing a variable from number to string kept the number bit it was loaded with and added the string bit. The save code tests the number bit first, so the variable was written with its text value and the type "number". The old type bits are now cleared before the type chosen in the dialog is set.

The team loadout reads the variables it uses by type when a mission loads, so with the type really saved, a changed one stopped the mission from loading. OK now refuses a type change for a variable the team loadout uses, which FRED's variable dialog refuses as well.
…e wing members alone

The Rename button on the selection toolbar passed whatever was typed straight to the rename code. A name already used by another ship was accepted, which also pointed that ship's references in events and goals at the shared name. A name of 32 or more characters hit the length assert in Debug and did not fit the ship's name field. The first is refused now by the ship editor's name check, the second by a length check.

The button was also offered for a wing member, whose name comes from its wing. Renaming one left the wing with a ship the pre-save check reports as an error. A wing member no longer gets the button.
…not changed

Clicking into the Ship Name box and leaving it without typing reset a custom display name, and the next save lost it. So did a rename the editor refused, such as another ship's name. The display name is now reset only when the ship's name really changes.
…ames

OK looked each variable up by its old name while earlier ones in the same pass had already been renamed. When two variables traded names, both found the same one: it ended up with the second variable's value and flags, and the first variable's value was lost. Every variable is now looked up before any is renamed.
…am loadout

Events, cues and the team loadout refer to a variable by name, and renaming one in the variables editor left them on the old name. An event then saved the variable as undefined, and a team loadout count or class saved with a name that no longer existed, which hit an assert while saving in Debug. OK now renames those references in the mission as well, the same way container renames already reach events. An event editor that is open at the time keeps its own copy and still writes the old name back when it is closed with OK, as it does for container renames.
OK found variables by name without regard to case, and also matched slots whose variable was already deleted, since a deleted slot keeps its name. In a mission with both Cancer and cancer, OK with nothing changed saved cancer's value under both names and lost Cancer's, and deleting cancer deleted nothing. After deleting a variable and giving its name to another in one OK, the next OK brought the deleted one back as a second variable of that name. Variables are now found with the engine's own lookup, which matches the exact name among the variables in use, as the game and the save code do.
…not changed

Leaving the Wing Name box without changing it still renamed the wing to its own name, which resets the display name, and the dialog then showed <none> in the Display Name box. Tabbing on through that box saved <none>, and the custom display name was lost. The wing is now renamed only when its name really changes, and the Display Name box is only refreshed then, as FRED does.
FRED renamed a variable only in the sexp tree it was renamed from. Events and cues held elsewhere, and the team loadout, which refers to a variable by name, stayed on the old name. After a rename from a wing's cue, saving showed "Couldn't find variable" warnings for the events and the file was not written. After a rename of a ship pool count variable, the next save (the autosave when the events editor closed) hit an assert in Debug builds; Release reads before the start of the variable list there. The reference update that qtFRED gained in the previous commits now sits beside the loadout counter in the shared editor code, and both editors call it.
@dustinspace217 dustinspace217 changed the title P3: Fix four more data-loss bugs in qtFRED P3: Fix more data-loss bugs in qtFRED, and a variable rename crash in both editors Nov 11, 2026
This reverts 2777a2f. scp-fs2open#8030 makes the same change to WingEditorDialogModel::setArrivalTarget and also shares the minimum distance rule between the editors, so this copy is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant