Skip to content

Various fixes for qtFRED - #8030

Open
The-E wants to merge 26 commits into
scp-fs2open:masterfrom
The-E:fix/qtfred-various-fixes
Open

The-E wants to merge 26 commits into
scp-fs2open:masterfrom
The-E:fix/qtfred-various-fixes

Conversation

@The-E

@The-E The-E commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

This PR fixes several issues that were never reported to the SCP. They are based on the description of fixes in the OFP fork, but no code from OFP was used in development; these are clean-slate reimplementations.

Full list of included changes:

Crashes and data loss

  1. Initial Status dialog with several ships
    • Bug: OK wrote hull, shields, and velocity as 101 to all marked ships. It also gave all of them the guardian threshold and team color of the first ship. OK could crash, because the dock data was not set up in multi-edit mode.
    • Fix: a field with different values shows "-", and OK keeps each ship's own value for it. The dock update runs only when the dialog edits one ship.
  2. Autosave recovery
    • Bug: after a recovery, the mission's save path pointed into the autosave folder, so Save wrote there. On Windows, the path separator could trigger an assert.
    • Bug: a failed recovery gave an empty mission bound to the original file, so Save or the autosave timer could write the empty mission over it.
    • Bug: two missions with the same file name shared one autosave.
    • Bug: Revert offered the autosave and could restore the changes that the user had just discarded.
    • Fix: the recovered mission keeps the original file name and is marked as modified. A failed load gives an untitled mission. The autosave name contains a hash of the full path. Revert offers no recovery. The timer writes an autosave at each interval. A successful save, Revert, and Discard delete the autosave of the mission, and Save As also deletes the autosave of the old path. Revert and Discard also stop the timer until the next mission loads. The untitled autosave is deleted when another mission loads.
  3. Save As and templates
    • Bug: after Save As, the title still showed the old name. A cancelled Save As cleared the current file name. After Load Template, Save wrote over
      the mission that was open before.
    • Bug: a .fst file opened from the recent-files list or with -start_mission was saved as a plain mission over the template.
    • Fix: Save As updates the title and the recent-files list. Every template load gives an untitled mission.
  4. Failed save not reported (older defect)
    • Bug: when a save failed, the user saw no message and the modified flag was cleared, so the edits were lost at exit with no prompt.
    • Bug: the mission save ignored the result of the last rename. On Windows with "Create .bak file" off, rename() does not replace a file that exists, so the save did not change the mission file.
    • Fix: QtFRED shows an error and keeps the file name and the modified flag. The mission save reports a failed rename as an error. On Windows with backups off, it deletes the old mission file before the rename. FRED2 uses the same code and also reports the error.
  5. FS1 import could overwrite the source file (older defect)
    • Bug: if the conversion failed, the .fsm source file became the save target.
    • Fix: an import gives an untitled mission.
  6. Crash at exit
    • Bug: QtFRED freed the mission and SEXP data while editor windows still used it. It never closed the Lua scripting system. Closing the campaign editor could trigger the Qt assert "Called object is not of the correct type".
    • Fix: QtFRED closes and deletes the editor windows first, then shuts down Lua, sound, and graphics in that order. The order is shared with FRED2. The campaign editor and its graph disconnect their signals in their destructors.
  7. Lua AI goals at exit (older defect, engine code)
    • Bug: AI goals of Lua AI modes kept Lua values after the Lua state closed. At exit, their destructors used the freed state.
    • Fix: the AI goal arguments are freed when the Lua state closes. This also applies to the game.

Editor behavior

  1. Selection groups overlapped
    • Bug: QtFRED used the group numbers 1–9 as bit masks, so group 3 was the same as groups 1 and 2.
    • Bug: ships in no group (value -1) matched every group. This also happened in FRED2.
    • Fix: each group is one bit, the same as FRED2, and a ship in no group matches no group. A ship that leaves its last group gets -1 again. QtFRED and FRED2 share this code.
  2. Wing arrival distance reset to 0
    • Bug: a new arrival target set the distance to 0, so the save check failed.
    • Fix: the distance stays, unless it is below the minimum for the target.
  3. Arrival distance minimum (older defect)
    • Bug: with a special anchor such as , a distance of 0 was still possible in the wing editor and the ship editor.
    • Bug: the ship editor computed the minimum from the radius of the arriving ships. FRED2 and the wing editor use the radius of the target ship.
    • Fix: each location near a ship needs a distance of at least 1, also with no target. Both ship editors and both wing editors use one shared rule, based on the target ship's radius. Each marked ship gets the minimum for its own location and target, and a ship with a sufficient distance keeps it. A negative distance goes up to the minimum, because the parser changes a value of 0 or less to 1. Each editor shows one warning with the largest new distance.
    • Bug: in the QtFRED ship editor, the distance field had the Qt default maximum of 99. When the marked ships had different distances, the field showed the distance of the last ship, and a typed value equal to it did not change the other ships.
    • Fix: the distance field uses MixedValueSpinBox. It shows "-" when the marked ships have different distances. Its maximum is the same as in the wing editor.
  4. Typed value in a mixed spin box was lost (older defect)
    • Bug: in the Initial Status and Reinforcements dialogs, a field shown as "-" ignored a typed value equal to the minimum, for example a velocity of 0.
    • Fix: a new MixedValueSpinBox widget applies each value that the user enters and keeps it in the valid range. An untouched "-" field, also after Enter, keeps the value of each ship.
  5. Recent-files menu leak (older defect)
    • Bug: each update of the recent-files menu leaked up to 8 menu actions.
    • Fix: the menu owns its actions and deletes them.

Restructuring (no behavior change)

  • Editor now holds the save path and makes the autosave recovery decision, so FredView keeps no copy of either.
  • One function sets the save options for Save, the autosave, and the FS1 import.
  • Shared functions replace repeated code for the arrival-location check and the group bits.
  • The Lua goal cleanup moved to ailua.cpp, and the Initial Status multi-edit loop is shorter.

Compatibility notes

  • QtFRED used to save the group numbers 1–9 as numbers. QtFRED and FRED2 now read the saved value as a bit mask, the same as FRED2 always did. Thus, groups that an older QtFRED saved can show in different group slots.
  • Autosaves from older builds use the plain file name. The new name contains a path hash, so QtFRED does not offer the old autosaves. You can delete them from the autosave folder.

Tests

  • test/src/missioneditor/test_editor_rules.cpp examines the group bits and the minimum arrival distance.
  • test/src/ai/test_ailua.cpp examines that Script_system.Clear() frees the Lua AI goal arguments.

Follow-ups (not in this PR)

  • The Events editor reports changes when there are none, so the exit asks about them once.
  • MIN_TARGET_ARRIVAL_DISTANCE is the largest minimum, not a lower limit. A better name can come in a separate PR, because the game code also uses it. This PR only corrects its comment.

🤖 Generated with Claude Code

@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.

Thanks for these. I built master and this branch and ran qtFRED and the game on both.

What I could reproduce on master and saw fixed here:

  • Initial Status with two marked ships (SM3-06, Nebtuu and Lambda 2): master shows hull 100 instead of "-" and crashes on OK inside ShipInitialStatusDialogModel::apply(). Here both fields show "-", OK works, and each ship keeps its own velocity and hull in the saved file.
  • Selection groups (SM3-10, which has ships saved with +Group: 1, 2 and 4): Ctrl+3 marks 27 ships on master (groups 1 and 2) and the 7 ships in group 3 here.

Regression: opened and saved SM1-01, SM2-01, SM3-06, SM3-10, Training-3 and TSM-104 (MediaVPs 5.0.2) in both builds, and the saved files are identical apart from the timestamp. Game side: SM2-01 into gameplay and a clean exit on OpenGL and Vulkan, master vs this branch, with no new log warnings. Unit tests match master.

Not reproduced: the exit crash (master Debug and an ASan build both exit cleanly with the Events and Reinforcements editors open), the campaign graph assert (needs a debug Qt), and the Lua AI goal cleanup (no retail content uses Lua AI modes). The autosave, Save As, template, failed save and FS1 import changes I checked by reading only, and they look right. FRED2 is Windows only, so I couldn't run it; CI's MSVC jobs build it.

Two things need a change, both inline: the clang-tidy finding that turned CI red, and FRED2's ship editor still using the old arrival distance rule.

Comment thread qtfred/src/ui/FredView.cpp Resolved
dustinspace217 added a commit to dustinspace217/fs2open.github.com that referenced this pull request Nov 12, 2026
This reverts ec05013 and f3afffd. scp-fs2open#8030 fixes the same selection group bug in both editors with shared helpers that keep -1 for "no group", so saved missions do not change. Dropping this version avoids a conflict in FredView.cpp.
dustinspace217 added a commit to dustinspace217/fs2open.github.com that referenced this pull request Nov 12, 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.
@The-E The-E mentioned this pull request Nov 12, 2026
@The-E
The-E force-pushed the fix/qtfred-various-fixes branch 2 times, most recently from 78492ee to 9023734 Compare November 14, 2026 16:52

@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.

Thanks for turning both requests around: setSpinBoxValueOrBlank is static and FRED2's ship editor calls arrival_min_distance(). This round I built the branch (Release and Debug, 346 unit tests pass) and took SM2-01 into gameplay and out to a clean exit on OpenGL and Vulkan with this branch and master; all four exited with code 0 and no log problems. qtFRED wasn't built this round, so the editor points below are from reading the code.

Two things I'd like changed:

The autosave gate at qtfred/src/ui/FredView.cpp:288 assumes every edit sets _missionModified, but the Reinforcements, Mission Specs, Variables, Briefing and Asteroid models and onSetGroup() never emit missionChanged(), so an edit made only there now gets no autosave where master wrote one every interval. The gate also keeps a stale autosave after Revert or Discard, so the next open offers back the discarded changes; dropping the gate and deleting the mission's autosave after a successful save, on Revert and on Discard would fix both.

In MixedValueSpinBox.cpp:17 the mixed state sets the value to INT_MIN, and as I read it, Enter on an untouched "-" field emits that value (or the clamped minimum if Qt goes through valueFromText), which the Initial Status and Reinforcements slots pass straight to the model, where apply only skips 101. I couldn't run it to confirm the Qt side, but ignoring the mixed sentinel in those slots would keep each ship's own value either way.

Smaller:

  • fred2/wing_editor.cpp:733 is still on the old rule (no minimum for special anchors, truncation, negative distances kept), so item 10 and the comment at shipeditordlg.cpp:1289 aren't true yet; calling arrival_min_distance() there finishes it.
  • fred2/shipeditordlg.cpp:1290 casts m_arrival_location, which is -1 when the marked ships have different arrival locations, so nothing is clamped; each ship's own arrival_location and anchor would fix it.
  • ShipEditorDialogModel.cpp:1217 checks only the last marked ship's distance and then writes the minimum to every marked ship, and the new call at :1165 adds a location change as a trigger; raising each ship only when its own distance is too low fixes it.
  • code/missioneditor/common.cpp:147 leaves a ship at group 0 after its last bit is removed, and the save then writes +Group: 0; setting it back to -1 avoids that.
  • missionsave.cpp:2457 ignores the cf_rename results, so the new failed-save message can't see a failed replace with backups off; that predates this PR, so a follow-up is fine.
  • The new rules in common.cpp and the Lua goal handler have no tests; a small file next to test_object_bounds.cpp plus one that calls Script_system.Clear() with goal arguments set would pin them.
  • Autosaves written by older builds use the plain file name, so they're never offered again and stay in the folder; a fallback lookup or a note in the description would cover it.
  • Nits: arrival_location_uses_distance sits under get_special_anchor's doc comment (missionparse.cpp:8971), askToUseNewerAutosave is under private slots, mission_load_error is unused, the exit comment at FredView.cpp:2268 could mention Cancel at the mission prompt, and the description could say old qtFRED group numbers now read as bit masks.

@The-E

The-E commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Thanks for the second review. I made the changes in six commits, from 6a7cf07 to 53ab2da.

Autosave (FredView.cpp:288). I removed the gate. The timer writes an autosave at each interval again, the same as on master, so the Reinforcements, Mission Specs, Variables, Briefing and Asteroid editors need no change. A successful save, Revert, and Discard now delete the autosave of the mission. Save As also deletes the autosave of the old path or of the untitled mission. After a save, the interval starts again from zero. One case stays the same as on master: if you save and then do nothing for more than one interval, the next open offers an autosave with the same content.

MixedValueSpinBox. You read it correctly. For "-", valueFromText() gave INT_MIN, and the clamp then changed it to the real minimum. Now valueFromText() keeps "-" as the sentinel. A new isBlank() lets the Initial Status and Reinforcements slots ignore it, so each ship keeps its own value.

Arrival distance.

  • The QtFRED ship editor now examines each marked ship with its own location and target. It raises only the ships that are below their own minimum. setArrivalTarget() now does the check after it writes the new target to the ships.
  • FRED2's ship editor uses Ships[ship].arrival_location and arrival_anchor, not m_arrival_location. FRED2's wing editor now calls arrival_min_distance(). Both FRED2 editors raise a negative distance to the minimum, the same as QtFRED, because the parser changes a value of 0 or less to 1.
  • I also found a related problem in the FRED2 ship editor. In multi-edit mode, m_arrival_dist.fix() put the minimum of one ship into the field, and save() then copied it to each later ship. Now fix() runs only when the dialog edits one ship.

Smaller items.

  • Groups (common.cpp): A ship that leaves its last group gets -1 again. onSetGroup() now sends missionChanged().
  • Tests: I added two files. test/src/missioneditor/test_editor_rules.cpp tests the group bits and arrival_min_distance(). test/src/ai/test_ailua.cpp puts Lua values into the goal arguments, calls Script_system.Clear(), and expects the arguments to be empty.
  • Old autosaves: I did not add a lookup by the plain file name. With that lookup, two missions with the same name in different folders would share one autosave again. The PR description now has a note about this.
  • Nits: I fixed all of them. I moved the doc comment, took askToUseNewerAutosave out of the slots, removed mission_load_error, and added Cancel to the exit comment. The description now says that old QtFRED group numbers read as bit masks.
  • cf_rename results: I agree that this needs a follow-up. The Events editor prompt is also a separate fix. Both are now in the description under "Follow-ups".

Tests. The build passes with -Werror, and the unit tests pass (358, with the 11 new tests). I examined the changed lines with clang-tidy and fixed the one finding whose check also exists in clang-tidy 16. I did not do the editor steps in qtFRED this round. Thus, I did not test these in the editor: Enter on "-", the autosave deletion, and the per-ship warning. FRED2 builds only on Windows, so I examined the two FRED2 editors only by reading the code.

@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.

Thanks, everything from the second review is in. I built this head (Release and Debug, no warnings, 360 and 358 unit tests pass) and ran the three editor cases you could not run, in qtFRED on Linux with a copy of SM1-01:

  • Enter on a "-" field: Initial Status with two ships marked, Enter on the Hull field. Each ship kept its own hull and velocity in the saved file.
  • Autosave: written at each interval; gone after Save, after Revert, and after Discard at File > New. Reopening the mission showed no recovery prompt.
  • Arrival distance: two ships marked, one at 2000 and one at 30, then a new target whose minimum is 117. One warning, the first ship stayed at 2000 and the second went to 117.

The inline notes are about the new code. None of them blocks; the first one is the one I would look at before this merges.

Two small things I saw in those runs: after the "Value has been reset to this" box, the distance field still shows the old number (0, or 30 with two ships marked) while the saved value is right. And untitled_autosave.fs2 stays in the autosave folder after opening another mission from an untitled one.

Not run by anyone: the two FRED2 editors.

One overlap to know about: my #8039 also changes FredView::closeEvent and loadMissionFile. It closes the registered tool dialogs before the prompt and reopens them if the quit is cancelled; yours closes every editor window and deletes them before shutdown. The two fit together (mine first for the registered tools, then your loop for the rest, then your delete), and I will do that merge in #8039 once this lands.

Comment thread qtfred/src/ui/FredView.cpp Resolved
Comment thread qtfred/src/ui/FredView.cpp Resolved
Comment thread fred2/wing_editor.cpp Resolved

@Goober5000 Goober5000 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.

A few more notes on the current head. None of them repeat dustinspace217's comments.

Comment thread fred2/shipeditordlg.cpp Resolved
Comment thread qtfred/src/mission/Editor.cpp Resolved
Comment thread test/src/ai/test_ailua.cpp Resolved
Comment thread code/missioneditor/common.cpp Resolved
@The-E

The-E commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Thanks for the third round, and thanks for the editor runs. I applied the notes from dustinspace217, Goober5000 and Kestrellius in four commits, from c8650f4 to 3adc13e.

Mission save (missionsave.cpp). The save now examines the result of the last cf_rename(). If the rename fails, the save returns an error, so the "Save Failed" message shows and the autosave stays. On Windows with backups off, the save deletes the old mission file before the rename, because rename() there does not replace a file that exists. FRED2 uses the same code, and it already shows a message for a failed save. On a plain Save, QtFRED now deletes the autosave one time only.

Autosave timer. Revert and Discard now stop the timer. The next mission load or new mission starts it again. If the FS1 import is cancelled at a file dialog after a Discard, the timer starts again for the open mission. The untitled autosave is deleted when another mission loads.

Recovered autosave path (Editor.cpp). loadMission() now finds the mission file with cf_find_file_location() before it looks for the autosave. The recovery question, the save path and the autosave name all use that absolute path.

Ship editor distance (QtFRED). The distance field is now a MixedValueSpinBox. It shows "-" when the marked ships have different distances, also after a raise to the minimum. In that state, a typed value goes to each ship, also a value equal to the last ship's distance. I also found that the field had the Qt default maximum of 99. It now has the same maximum as the wing editor. I could not find the cause of the stale field after the warning by reading the code. With the maximum of 99, the field would show 99, not the old value. Please tell me if you still see it with this head.

Wing editors.

  • QtFRED setArrivalType() writes getMinArrivalDistance(), not 0, when there are no targets.
  • FRED2 wing_editor.cpp now does the minimum check outside if (m_arrival_target >= 0).

FRED2 ship editor. update_ship() now records the largest raise. update_data() shows one box after all the ships, and only when bypass_errors is not set.

Tests.

  • test_editor_rules.cpp has a case with radius 100.2 that expects 200.
  • test_ailua.cpp calls ai_lua_init() one time only. I used a static guard in SetUp(), so the call stays after the fixture setup.

MIN_TARGET_ARRIVAL_DISTANCE. Kestrellius, you are correct: the constant is the largest minimum. The comment in missionparse.h said "at least 500", which was wrong. I corrected it and added a comment in arrival_min_distance(). The game code also uses the constant, so I put the new name in the "Follow-ups" part of the description.

Verification. The build passes with -Werror. The unit tests pass (358, 1 skipped), and the new tests also pass with --gtest_repeat=3. clang-tidy has no findings on the changed lines. I did not run the editor cases in qtFRED this round. FRED2 builds only on Windows, so I examined the two FRED2 editors only by reading the code.

@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.

Re-checked at 3adc13e. My four notes are all fixed: a failed final rename now returns an error and keeps the autosave, Revert and Discard stop the timer, the FRED2 wing editor check is outside the target block, and the 100.2 case tells round from ceil.

On your question about the stale distance field: from reading this head, I think it's still there. The field only gets its value in updateUi() (ShipEditorDialog.cpp:337-339). That runs when the dialog opens and on shipMarkingChanged. modelChanged only calls initializeUi() (line 57), which never sets the field. So when a target or location change raises a ship, or leaves the marked ships with different distances, the field keeps the old number until the marking changes. The saved values are right. In the mixed case the field also shows one real number instead of "-", so typing that same number back sends no change. Refreshing the distance field after a change that raises or mixes the distances should fix it. I haven't rerun the editor at this head.

Minor: on Windows with backups off, the old file is deleted before the rename, so if the rename then fails, the mission file is missing until the next save. The edits stay in the editor, still marked modified, so another save can write them. A rename that replaces the existing file would close that gap.

The-E and others added 13 commits November 18, 2026 17:01
QtFRED gave the group numbers 1 to 9 to the group functions as bit
masks. Thus group 3 was the same as groups 1 and 2. Also, a ship in no
group has the value -1, and -1 has all bits set. Such a ship matched
each group in QtFRED and FRED2.

Each group is now one bit, the same as in FRED2. The new shared
functions ship_in_editor_group() and ship_set_editor_group() hold the
meaning of -1, and QtFRED and FRED2 both use them. A ship in no group
keeps -1, so the mission save writes no group data for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the user chose a new arrival target, the wing editor set the
arrival distance to 0, because the comparison was reversed. The save
check then failed with "Arrival distance for wing ... must be greater
than 0".

The distance now stays. The editor raises it to the minimum for the new
target only if it is smaller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wing editor and the ship editor each had their own copy of the
minimum arrival distance, and the copies were wrong in two ways:
- With a special anchor such as "<any friendly>", both editors accepted
  a distance of 0. The mission parser changes 0 to 1, and the error
  checker rejects it.
- The ship editor took the radius of the marked arriving ships. FRED2
  and the wing editor take the radius of the target ship.

arrival_location_uses_distance() in missionparse now gives the
locations near a ship. The parser, the error checker, and both models
use it. arrival_min_distance() in the shared editor code gives the
minimum: 0 for a location without a distance, at least 1 otherwise,
and min(500, 2 * target radius) near a real ship. The ship editor also
checks the distance when the arrival location changes, and it does not
accept negative distances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Initial Status and Reinforcements dialogs show "-" in a spin box
when the marked objects have different values. Two defects:
- In the Initial Status dialog, the "-" text stayed after the box got
  a real value, so a real value at the minimum (for example a velocity
  of 0) also showed "-".
- A typed value equal to the value under the "-" did not change the
  spin box, so Qt sent no signal and the dialog ignored the value.

The new widget MixedValueSpinBox (a QSpinBox subclass) keeps the mixed
state and the real minimum in members. setMixed() moves the minimum
below the real range, so each value that the user enters is a change.
The widget keeps typed values and arrow steps in the real range.
setSingleValue() ends the mixed state. Both dialogs use the widget as a
promoted widget, and the clamp code in the Reinforcements slots is
removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With several ships marked, OK in the Initial Status dialog damaged the
ships:
- The code checked the velocity flag three times and never used the
  shield and hull flags. So mixed values did not show blank, and OK
  wrote 101 (the blank marker) to the ships.
- OK gave the guardian threshold and the team color of one ship to all
  marked ships.
- OK could crash, because the dock update ran in multi-edit mode,
  where the dock data was never set up.

Now a field with different values shows blank, and OK keeps the value
of each ship for a blank field. This includes the guardian threshold
and the team color. The team color goes only to ships that use team
colors. The dock update runs only when the dialog edits one ship. The
multi-edit loop uses one ship reference and one merge function for the
check boxes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The goals of Lua AI modes keep Lua values (the extra SEXP arguments) in
Ai_info and Wings. Script_system.Clear() closes the Lua state, but these
values stayed. Their destructors ran later, for example at program exit,
and released references in the closed Lua state.

The new ai_lua_init() in ailua.cpp registers an OnStateDestroy handler
that frees these arguments while the Lua state still exists. ai_init()
calls it once. This applies to the game and to the editors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
QtFRED freed the mission and SEXP data while editor windows still used
it, because WA_DeleteOnClose deletes a window only after shutdown().
QtFRED and FRED2 also never closed the Lua scripting system. Closing the
campaign editor could trigger the Qt assert "Called object is not of
the correct type", because the graph scene sent selectionChanged to the
half-destroyed graph.

On exit, QtFRED now closes the editor windows first, so each one can ask
about its own changes. After the mission prompt, it deletes them, then
it shuts down the engine. The new shared editor_shutdown() frees the
engine and SEXP data, closes the Lua state (in the same order as
game_shutdown()), then sound, then graphics. QtFRED and FRED2 both use
it, and FRED2 no longer closes sound in CFREDView::OnDestroy. The
campaign editor and its graph disconnect their child signals in their
destructors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each update of the recent-files menu created up to 8 new menu actions
with the main window as parent. QMenu::clear() did not delete them, so
they leaked.

The menu now owns its actions. The update removes the old actions and
deletes them later, because a recent-file action can start the update
while it sends its own triggered() signal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three defects in the save path:
- After Save As, the window title still showed the old file name.
- A cancelled Save As cleared the current file name, because the
  dialog result went directly into the member.
- A template load kept the save path of the mission that was open
  before, so Save wrote over that mission. A .fst file opened from the
  recent-files list or with -start_mission loaded as a plain mission,
  so Save wrote over the template.

Editor now holds the save path. Editor::loadMission() makes each .fst
file a template and gives a template no save path. FredView::saveName
is removed; FredView reads Editor::currentMissionPath(). Save As uses a
local variable, sets the new path only after the save, and updates the
title and the recent-files list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The FS1 import loads the .fsm file and then saves it as an FS2 mission.
The load made the .fsm file the save path. If the conversion save
failed, the mission stayed loaded, and Save wrote FS2 data over the FS1
source file.

An FS1 import now gives an untitled mission. After a successful
conversion, the import loads the converted file as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Several defects in the autosave recovery:
- After a recovery, the save path pointed to the file in the autosave
  folder, so Save wrote there. On Windows, the '/' separators from
  QStandardPaths could trigger the CFile assert "We have full path, but
  no separator!?".
- Two missions with the same file name in different folders shared one
  autosave, so the recovery could load the wrong mission.
- The timer wrote an autosave also without unsaved changes. The next
  load then offered a recovery of content that was already in the
  file, and Revert could bring back the changes that the user had just
  discarded.

Editor::loadMission() now owns the recovery. It asks about a newer
autosave, loads it with native separators, and keeps the original
mission path as the save path. missionLoaded() tells FredView that the
content is not saved yet, so the mission shows as modified. A failed
load gives an untitled mission. The autosave name contains a hash of
the full mission path. The timer writes an autosave only for unsaved
changes, and Revert does not offer a recovery. The dead catch block in
loadMissionFile() is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
save_mission_file() only writes to the log when it fails. Save and
Save As ignored its result: they cleared the modified flag and set the
last-saved time also after a failure. The user saw no message, and
QtFRED then closed without a prompt, so the edits were lost.

The new writeMissionFile() checks the result. On failure, it shows an
error and keeps the modified flag. Save As then also keeps the old file
name. configureMissionSave() now sets the save options in one place for
Save, the autosave, and the FS1 import, and reportPreSaveFixes() shows
the pre-save check result for Save and Save As.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The function does not use this. The clang-tidy job reports it as
readability-convert-member-functions-to-static.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The-E and others added 13 commits November 18, 2026 17:10
The ship editor used the radius of the arriving ship and accepted a
distance of 0 for a special anchor. The wing editors and QtFRED use the
radius of the target. Use the shared rule so the editors agree.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The autosave gate needed the modified flag. The Reinforcements, Mission
Specs, Variables, Briefing, and Asteroid editors do not set it, so an
edit in only these editors got no autosave. The gate also kept a stale
autosave after Revert or Discard, and the next load offered the
discarded changes again.

Write the autosave at each interval, the same as before. A successful
save, Revert, and Discard now delete the autosave of the mission. Save
As also deletes the autosave of the old path. After a save, the
interval starts again. askToUseNewerAutosave() is no longer a slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the mixed state, the value of the spin box is a sentinel below the
real range. Enter on an untouched "-" field went through
valueFromText(), which clamped "-" to the real minimum. The slots then
gave that value to the model, so each marked ship got it.

valueFromText() now keeps "-" as the sentinel. The new isBlank() tells
the Initial Status and Reinforcements slots to ignore the sentinel, so
each ship keeps its own value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The QtFRED ship editor examined only the distance of the last marked
ship, and then wrote its minimum to each marked ship. It also examined
the target before it wrote the new target to the ships. FRED2's ship
editor used the dialog's arrival location, which is -1 when the marked
ships have different locations, so it did no check. FRED2's wing editor
still used the old rule.

Each ship and wing now gets the minimum for its own location and
target, and a ship with a sufficient distance keeps it. A negative
distance goes up to the minimum, because the parser changes a value of
0 or less to 1. In multi-edit mode, FRED2 does not write the minimum of
one ship into the field, because save() copies the field to each ship.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A ship stayed at group 0 after its last group bit was removed, and the
mission save then wrote "+Group: 0". Set it back to -1 ("in no group").
QtFRED's Set Group also marks the mission as changed now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new editor tests examine the group bits and arrival_min_distance().
The Lua test puts Lua values into the AI goal arguments, calls
Script_system.Clear(), and makes sure that the arguments are empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the doc comment of get_special_anchor() back to its function.
Remove the unused mission_load_error. Mention Cancel at the mission
prompt in the exit comment. Make the recent-files loop variable const,
for misc-const-correctness.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mission save ignored the result of the last rename. On Windows with
backups off, rename() does not replace a file that exists, so the save
did not change the mission file. Delete the old file first on Windows,
and return an error if the rename fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The timer could write the discarded changes again while a dialog stayed
open. The next load starts the timer again. A plain Save now deletes the
autosave one time only. The untitled autosave is deleted when another
mission loads. A recovered autosave now uses the absolute mission path,
the same as a normal load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- QtFRED ship editor: the distance field shows "-" when the marked
  ships have different distances, and its maximum is no longer 99.
- QtFRED wing editor: with no targets, the distance gets the minimum.
- FRED2 wing editor: the minimum check also runs with no target.
- FRED2 ship editor: one warning after all the ships, and only when
  bypass_errors is not set.
- Correct the comment of MIN_TARGET_ARRIVAL_DISTANCE. It is the largest
  minimum, not a lower limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A radius of 100.2 tells round from ceil. ai_lua_init() adds a handler
to the global Script_system, so call it only one time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The distance field got its value only when the dialog opened or the
marking changed. When a target or location change raised a ship to its
minimum, or left the marked ships with different distances, the field
kept the old number. The saved values were correct.

The dialog now refreshes the distance field after each model change. It
changes the field only when the field shows a different value. The field
also sends its value only on Enter or focus loss. Before, each key press
sent a value, so the minimum check could raise a part of a typed number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows with backups off, the save deleted the old mission file and
then renamed the temporary file. If that rename failed, the mission file
was missing until the next save.

cf_rename() has a new replace_existing parameter. On Windows it uses
MoveFileExA() with MOVEFILE_REPLACE_EXISTING. POSIX rename() already
replaces a file. The mission save uses it, so a failed rename keeps the
old mission file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@The-E
The-E force-pushed the fix/qtfred-various-fixes branch from 3adc13e to 179b098 Compare November 18, 2026 16:12
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.

4 participants