This pull request's diff hasn't been prepared yet. Log in with GitHub to have us prepare it for review.

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

Merged
ljharb opened 8:59am on September 21, 2026 wanted to merge 15 Ξ” into mltframework/shotcut master from
copilot/fix-crash-when-adding-subtitles

Pull Request Overview

  • Opened on September 21, 2026
  • Status Merged
  • Commit count 3 with first commit September 21, 2026

Total Delta

15 Total Diff Delta

Open Days

Open 40 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
N/A 1.6 days Issue creation to work beginning
 
0.0 days Authoring 1 commit before pull request opened for review
 
0.8 days Awaiting first review
Set up deploy tracking to begin tracking full PR start-to-deploy times

Total time for pull request 0.8 business days from first commit authored to merge
Deploy tracking has not been set up

Author avatar

Avoid invalid subtitle add/remove paths near project end

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();
}


  • Fixes #1912

OS and Version (please complete the following information): - Operating System: Windows 11 Pro (build 26200) - Shotcut Version: 26.8.1 (official Windows x64 installer)

Describe the bug

Shotcut terminates with an unhandled access violation, with no error dialog, after the Add Subtitle action is invoked repeatedly while the status bar reports "Not enough space to add subtitle."

Windows Error Reporting logged two crashes with an identical signature:

Faulting application: shotcut.exe, version 26.8.1.0, timestamp 0x6a6dc118
Faulting module:      shotcut.exe, version 26.8.1.0, timestamp 0x6a6dc118
Exception code:       0xc0000005      (access violation)
Fault offset:         0x000000000028d0d3

Both crashes landed in the same WER bucket, so it appears deterministic rather than a race.

Observed sequence (from shotcut-log.txt)

[Debug] <SubtitlesDock::onAddRequested>
[Debug] <Subtitles::InsertTrackCommand::redo> "Subtitle Track 1"
[Info ] <MainWindow::showStatusMessage> "Not enough space to add subtitle."
[Debug] <SubtitlesModel::doRemoveTrack> 0
[Debug] <SubtitlesDock::onAddRequested>
[Debug] <Subtitles::InsertTrackCommand::redo> "Subtitle Track 1"
[Info ] <MainWindow::showStatusMessage> "Not enough space to add subtitle."
[Debug] <TimelineDock::setSelection> Changing selection to QList()  trackIndex -1 isMultitrack true
[Debug] <SubtitlesDock::onAddRequested>
[Debug] <Application::~Application> exiting

The UI language was pt-BR; the two status messages are translated back to English here. Note that the third onAddRequested emits no further output before the process dies.

Steps To Reproduce

These are reconstructed from the log rather than from a minimized test case, so the exact number of repetitions may vary:

  1. Start Shotcut and append a clip to the timeline
  2. Move the playhead to within 500 ms of the end of the project
  3. In the Subtitles panel, use Add Subtitle β€” the status bar shows "Not enough space to add subtitle."
  4. Invoke Add Subtitle again, two more times
  5. Shotcut exits silently

Expected behavior

The rejected action should be a no-op beyond the status message, and repeating it should remain a no-op.

Possible causes

Offered as leads from reading the source only β€” I have not attached a debugger to confirm either one.

  1. SubtitlesDock::onAddRequested() (src/docks/subtitlesdock.cpp:773) calls ensureTrackExists() before validating the available space, then returns early on the "not enough space" path. Every rejected attempt therefore leaves a newly created subtitle track behind.

  2. SubtitlesModel::doRemoveTrack() (src/models/subtitlesmodel.cpp:592) detects an out-of-range index but only logs it β€” there is no return, so execution falls through into the removal with the invalid index:

if (trackIndex < 0 || trackIndex >= m_tracks.size()) {
    LOG_ERROR() << "Invalid index" << trackIndex;
}
beginRemoveRows(QModelIndex(), trackIndex, trackIndex);
m_tracks.remove(trackIndex);
m_items.remove(trackIndex);

The WER minidump is available if it would help.

Comments Threads Pending Resolution

bmatherly reviewed and approved this work on September 22, 2026
bmatherly left a comment

This looks good.

Resolved Comment Threads

No resolved comments have been left on this PR.