Bug 507849 - Crash when undoing clip replacement
Summary: Crash when undoing clip replacement
Status: CONFIRMED
Alias: None
Product: kdenlive
Classification: Applications
Component: Timeline & Editing (other bugs)
Version First Reported In: git-master
Platform: Neon Linux
: NOR crash
Target Milestone: ---
Assignee: Jean-Baptiste Mardelle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-04 12:15 UTC by Bruno Santos
Modified: 2025-08-07 05:15 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
gdb backtrace (64.69 KB, text/plain)
2025-08-04 12:15 UTC, Bruno Santos
Details
Video showing the timeline changes (3.66 MB, video/mp4)
2025-08-04 12:16 UTC, Bruno Santos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Santos 2025-08-04 12:15:07 UTC
Created attachment 183777 [details]
gdb backtrace

SUMMARY
When trying to replace a clip but keep the cuts done to the current clip, I get changes to the cuts (most disappear), and a crash undoing this action.

STEPS TO REPRODUCE
1. Replace clip that was cut using the multi monitor tool
2. Cuts in the timeline change to a seemingly unstable state
3. Undo the clip replacement

OBSERVED RESULT
Clips in the timeline change or disappear and then kdenlive crashes.

EXPECTED RESULT
The clip in the Bin is changed back to the original clip. The timeline segments/cuts of the clip stay as they were.

SOFTWARE/OS VERSIONS
Operating System: KDE neon Testing Edition
KDE Plasma Version: 6.4.3
KDE Frameworks Version: 6.17.0
Qt Version: 6.9.1
Kernel Version: 6.14.0-27-generic (64-bit)
Graphics Platform: Wayland
Processors: 12 × Intel® Core™ i7-8750H CPU @ 2.20GHz
Memory: 32 GiB of RAM (31,2 GiB usable)
Graphics Processor 1: Intel® UHD Graphics 630
Graphics Processor 2: NVIDIA GeForce GTX 1050
Manufacturer: HP
Product Name: OMEN by HP Laptop 15-dc0xxx
Comment 1 Bruno Santos 2025-08-04 12:16:28 UTC
Created attachment 183778 [details]
Video showing the timeline changes
Comment 2 Jean-Baptiste Mardelle 2025-08-05 05:22:30 UTC
Thanks for the report. I think this only occurs if you replace a clip with another shorter one. Will investigate
Comment 3 Jean-Baptiste Mardelle 2025-08-07 04:36:02 UTC
Ok, so this was an interesting issue! The problem happened when you replaced a clip with another shorter clip. 
There is an issue in our undo system, because loading a clip (or replacing it) triggers an asynchronous task (a QRunnable) to load the clip, and that task can take a few seconds. So when quickly undoing  several operations, we could end up in a situation where the operation before the clip replacement was performed before the clip was actually ready, using the previously stored clip leading to unstable state and crash.

Example:
* Clip A, 600 frames
* Clip B, 300 frames

We have clip A in timeline, without cut.

Replacing clip A with clip B in the project Bin will trigger these operations :

1. Resize timeline clip from 600 to 300 frames
2. Replace timeline producer from clip A to clip B

When quickly undoing the 2 operations, as described it can happen that we try to perform operation 1 before the replacement of clip B with clip A is finished. So operation 1 will use clip B and fail because clip B cannot be resized from 300 to 600.

I have not yet found a good design fix for this, so my current workaround (that I will probably push today) is to temporarily disable undo, when replacing a clip. It means that if you try to quickly undo several operations, if there is a clip replacement operation, all later calls to undo will be ignored and canceled until the replace operation is completely done.

It can be a bit annoying as you might have pressed the undo shortcut twice and Kdenlive will only undo one operation, and you need to press undo again after 1-2 seconds, but still better than a crash.
Comment 4 Jean-Baptiste Mardelle 2025-08-07 05:15:48 UTC
Git commit 75dc2f9c96f0585eeb4fccc8f7b333b7d7ff47cf by Jean-Baptiste Mardelle.
Committed on 07/08/2025 at 05:15.
Pushed by mardelle into branch 'release/25.08'.

Disable undo while processing a clip replacement to prevent corruption on undo operation

M  +11   -0    src/bin/projectclip.cpp
M  +5    -8    src/mainwindow.cpp
M  +1    -0    src/timeline2/model/clipmodel.cpp

https://invent.kde.org/multimedia/kdenlive/-/commit/75dc2f9c96f0585eeb4fccc8f7b333b7d7ff47cf