Skip to content

Avoid invalid subtitle add/remove paths near project end - #1916

Merged
ddennedy merged 2 commits into
masterfrom
copilot/fix-crash-when-adding-subtitles
Sep 22, 2026
Merged

ddennedy merged 2 commits into
masterfrom
copilot/fix-crash-when-adding-subtitles

Conversation

Copilot AI commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Repeated Add Subtitle attempts near the end of the project could leave behind an empty subtitle track after the action was rejected for insufficient space, and subtitle track removal still executed after detecting an invalid index. This change makes rejected adds a true no-op and hardens track removal against out-of-range access.

  • Add Subtitle no longer creates tracks on rejection

    • SubtitlesDock::onAddRequested() now checks timing constraints before calling ensureTrackExists() when no subtitle track exists.
    • Repeated "Not enough space to add subtitle." actions no longer mutate subtitle-track state.
  • Existing-track behavior stays intact

    • Duplicate detection and next-item gap calculation still run for a valid selected track.
    • Track creation is deferred until insertion is actually possible.
  • Invalid subtitle track removal now exits immediately

    • SubtitlesModel::doRemoveTrack() now returns after logging an invalid index instead of falling through into beginRemoveRows() / container removal.
if ((maxTime - msTime) < 500) {
    MAIN.showStatusMessage(tr("Not enough space to add subtitle."));
    return;
}

if (trackIndex < 0) {
    ensureTrackExists();
    trackIndex = m_trackCombo->currentIndex();
}

Co-authored-by: ddennedy <1146683+ddennedy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash due to access violation when adding subtitles Avoid invalid subtitle add/remove paths near project end Sep 21, 2026
Copilot AI requested a review from ddennedy September 21, 2026 17:04
@ddennedy
ddennedy requested a lite review from Copilot September 21, 2026 17:17

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The reviewed changes address the identified subtitle-track state and bounds issues.

Review effort: Lite
Findings: None

What changed in this PR

Prevents invalid subtitle-track mutations when adding subtitles near the project end and safely handles invalid track removal.

Changes:

  • Defers track creation until subtitle insertion is valid.
  • Returns immediately for invalid subtitle-track indices.
File Description
src/​models/​subtitlesmodel.cpp Stops invalid track removal before model/container access.
src/​docks/​subtitlesdock.cpp Validates available space before creating a subtitle track.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ddennedy
ddennedy marked this pull request as ready for review September 21, 2026 17:58
@ddennedy ddennedy added this to the v26.9 milestone Sep 21, 2026
@ddennedy
ddennedy requested a review from bmatherly September 21, 2026 17:59

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

This looks good.

@ddennedy
ddennedy merged commit fdbbbc4 into master Sep 22, 2026
5 checks passed
@ddennedy
ddennedy deleted the copilot/fix-crash-when-adding-subtitles branch September 22, 2026 03:15
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.

Crash (access violation) when Add Subtitle is repeated after "Not enough space to add subtitle"

4 participants