Skip to content

P3: qtFRED campaign editor: fix crash on close and leftover drag trails - #8004

Merged
The-E merged 8 commits into
scp-fs2open:masterfrom
dustinspace217:qtfred/campaign-graph-teardown-redraw
Nov 16, 2026
Merged

The-E merged 8 commits into
scp-fs2open:masterfrom
dustinspace217:qtfred/campaign-graph-teardown-redraw

Conversation

@dustinspace217

@dustinspace217 dustinspace217 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What?

Two fixes in qtFRED's campaign editor graph. Fixes #7730 and #7728.

Why?

  • Closing qtFRED (or the campaign editor) with a mission selected could crash during cleanup.
  • Dragging missions around left fragments of ports and arrowheads on screen until something forced a full repaint, like the screenshots in qtFred Bug: Campaign Editor Graphical Issues #7728.

How?

  • The graph view owns its scene as a child, so the scene is deleted after the view's destructor has already run. Deleting it clears the selection, which called the view's selection slot on an object that was half destroyed. The destructor now disconnects the scene first.
  • Qt only repaints an item's bounding rectangle. Mission cards drew their ports half outside theirs, edges drew arrowheads outside the path's bounds, and the END pill's top port reached past its bounds by its pen width. I grew each bounding rectangle to cover what it draws.
  • A card's shape() stays the old rectangle, so clicks, drops and the places that position things from the card (self-loops, the END pill) behave as before.

Testing?

  • Built qtFRED warning-free in Release and Debug, and CI's clang-tidy is clean on the changed lines.
  • The crash: I couldn't get it to crash on Linux even on master, since freed memory is often still readable there. So I built a small standalone Qt program with the same ownership and connection. On master's shape the selection slot runs a second time during deletion; with the disconnect it doesn't.
  • The redraw trails: I couldn't drive the campaign graph in my headless setup (the cards didn't draw there), so this part is checked by reading the paint code against the new bounds, not by eye.
  • Worth a hand check on Windows: open a campaign, select a mission, close qtFRED; and drag missions and the END pill around with edges attached, looking for leftover pixels.

Anything Else?

… arrows in the bounds

The graph view owns its scene as a child, so the scene is deleted after
the view's destructor has run. Clearing the selection during that
deletion called the view's selection slot on an object that was
already half destroyed, which crashed the editor on close when a
mission was selected. Disconnect the scene first.

Mission cards drew their ports half outside their bounding rectangle,
edges drew arrowheads outside the path's bounds, and the END pill's
port pen reached past its top. The view only
repaints bounding rectangles, so dragging left fragments behind. Grow
both bounds to cover what they draw; a card keeps its old shape for
clicks and drops.

Fixes scp-fs2open#7730
Fixes scp-fs2open#7728

@TheForce172 TheForce172 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code itself looks good to me but I'm not in a situation where I can build right now so I have not seen what the graphical changes have

… item type

Dropping a connection just above the END pill now creates a new mission
again: the pill and the drop checks use the pill's own rect, not the
larger paint bounds. Layout reads a cardRect() accessor instead of
shape(), the border padding is one shared constant, and the view
removes its application event filter when it is destroyed.

MissionNodeItem declared no Qt item type, so qgraphicsitem_cast let any
scene item through as a mission card. A drop or right-click on the END
pill or on a branch line was handled as if it hit a card, reading a
mission index from an object that has none. Cards now have their own
type, so those clicks fall through to the END and empty-space handling.
… scene with the view

Half of each port is drawn outside its card, and a card's hit shape was
the card alone. Dropping a connection on the upper half of an inbound
port created a new mission instead of a branch, and pressing the lower
half of an outbound port panned the view instead of starting a
connection. The hit shape now includes the three ports. The END pill
gets the same treatment for its one port, and the two END checks ask
the item whether it contains the point.

The view disconnected the scene's signals on close but left the scene
to be deleted later as a child. The scene's items are connected to the
view too, so anything one of them sent while being deleted would have
reached a view whose own part was already gone. The view now deletes
the scene in its destructor.
… guard comment

The END pill builds its rect in one place, and its padding follows the
width of the pen it draws with. The bounds check where a connection
drag starts no longer mentions dragging the END pill, which the item
type check now rules out, and uses in_bounds(). The border constant's
comment says what the padding covers.
…ble drag-start guard

The destructor comment now covers both the disconnect and the delete,
and the two shape comments say why the paths use winding fill. The
bounds check where a connection drag starts is removed with its
comment: cards are built from the model's mission list and rebuilt on
every change to it, so a card's index is always in range.
…ton only

A right or middle press on an outbound port started a connection drag,
because the press handler never looked at the button. After the card
menu closed, the preview line followed the mouse with no button held,
and the next release could add a branch or open the new-mission
picker. This was already so on the part of a port inside its card; the
port halves outside the card now reach the same handler.

The port hit circles also take in half the outline's width, so the
drawn ring is part of the port.
@dustinspace217

Copy link
Copy Markdown
Contributor Author

Pushed four commits for the latest review notes.

The two "worth raising" points

  1. Port halves outside the card now work. Each card's hit shape includes its three ports, and the END pill's includes its one. A drop on the upper half of an inbound port makes the branch, and a press on the lower half of a main or special port starts a connection. I did this in the items' shape() instead of a distance test in the view, so clicks, drops, right-clicks and the hover cursor all agree. One difference from a distance test: outside the card only the drawn port counts, while inside the card the wider radius still applies.
  2. The view deletes its scene in its destructor, right after disconnecting it. That covers signals from the scene's items to the view. It doesn't cover a signal the view would pass on to the dialog, since the dialog's own members are already gone by then. Nothing does that today.

Side effects of 1

  • Pressing the outside half of an inbound port selects and moves the card, the same as the inside half.
  • Right-clicking a port half opens the card menu.
  • The top half of the END port acts like the pill: no menu, and a loop drag dropped there does nothing.

Also fixed

  • A right or middle click on a main or special port started a connection, because the press handler didn't check the button. After the menu closed, the preview line followed the mouse and the next release could add a branch. Connections now start and finish with the left button only. On master this already happens on the inside half of a port.
  • Cleanups 3 to 7 from the list. For 6 I removed the guard, since every change to the mission list is followed by a rebuild of the cards.

Testing

qtFRED on Linux, Release and Debug, with the retail campaign file, driven through an automated harness on a virtual display (not by hand):

  • Drag from the outside half of a main port to the outside half of another card's inbound port: the branch is created. On master the press pans the view, and a drop there opens the new-mission picker.
  • The same from the loop port: a loop branch is created.
  • Right-click and middle-click on a port, then move the mouse: no preview line. Before the fix there was one.
  • Close the campaign editor with a card selected, reopen it, close it again: fine in both builds.

Not tested: Windows, macOS, and the hover cursor.

Right-clicking while a connection was being dragged opened the card or
empty-space menu, and the menu took the left release that would have
ended the drag. Afterwards the preview line followed the mouse with no
button held. The drag is now cancelled when the context menu event
arrives. That includes an event over the END pill, where no menu opens.

cancelDrag() now restores the hand-drag mode itself, so finishing a
connection and this cancel both get it from one place.
@dustinspace217

Copy link
Copy Markdown
Contributor Author

One more small commit (048db80). While testing the last round I found that right-clicking during a connection drag left the preview line stuck to the mouse: the menu took the left release that would have ended the drag. Master does the same.

The drag is now cancelled when the context menu event arrives, and cancelDrag() restores the hand-drag mode itself. Two things to know:

  • Over the END pill no menu opens, but the drag is still cancelled there. One rule seemed better than an exception for END.
  • I could only test on Linux, where the menu comes on the right press. Where it comes on the right release (Windows), a left release that happens first just finishes the connection as before.

Tested by hand in qtFRED (Release): a right-click during a drag over a card, over empty space and over END, with Escape, with the left button released while the menu was still open, and with the keyboard menu key; "Delete mission" on the card the drag started from, then a pan and a normal connection. No preview line is left behind in any of them, no card moves, and the next connection makes exactly one branch. Release and Debug build without warnings.

@The-E
The-E merged commit 9c7334a into scp-fs2open:master Nov 16, 2026
18 checks passed
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.

qtFred Bug: Campaign Editor Closing cleanup crash

3 participants