fix(editor): read inserted frames before a render embeds the project
A render queued before the editor had seen frames inserted under it (a sync download, an import of earlier photos, a scan without an event) embedded the project's positions in the old frame order. Render now checks first that the frames read are still the sequence's (ISequenceSource.FramesCurrentAsync: the row's frames version on this PC, the manifest on a server). On this PC the sequence is read again and the positions follow the frames; a server sequence whose frames changed turns outdated and the render is not queued. Reads of the sequence no longer overlap: a read waits for the one under way, saves that meet new frames read them through the same slot, and they save the project as it is once its positions followed. The frame on screen stays on its photo when frames are inserted or removed before it. Tests: the event-loss test waits for the listener's subscription before dropping the stream, and the conflict tests flush once more after the choice when a retry started before it was still failing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
11 files changed
+351
-31
No files matched your search
@@ -48,6 +48,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
private readonly AsyncRelayCommand _cancelServerJob;
|
||||
private PreviewRenderer _renderer;
|
||||
private int _currentIndex;
|
||||
|
||||
/// <summary>The frame on screen: it stays on screen when frames are inserted or removed before it.</summary>
|
||||
private Guid _currentFrameId;
|
||||
private EditorTab _selectedTab;
|
||||
private ImageSource? _previewImage;
|
||||
private ImageSource? _originalImage;
|
||||
@@ -111,6 +114,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
Tabs = [Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)];
|
||||
_selectedTab = Exposure;
|
||||
_currentIndex = session.Project.HeroFrame is { } hero && (uint)hero < (uint)FrameCount ? hero : 0;
|
||||
_currentFrameId = FrameId(_currentIndex);
|
||||
// Until the link is read (AttachJobsAsync), a sequence of this PC cannot send its renders.
|
||||
_syncGate = session.IsRemote ? ExportSyncGate.Remote : ExportSyncGate.SignedOut;
|
||||
RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))];
|
||||
@@ -233,6 +237,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
set
|
||||
{
|
||||
var clamped = FrameCount == 0 ? 0 : int.Clamp(value, 0, FrameCount - 1);
|
||||
_currentFrameId = FrameId(clamped);
|
||||
if (!Set(ref _currentIndex, clamped)) return;
|
||||
foreach (var tab in Tabs) tab.OnCurrentFrameChanged();
|
||||
UpdateInfo();
|
||||
@@ -515,6 +520,10 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
/// </summary>
|
||||
public async Task RenderAsync(JobPriority priority, bool batch)
|
||||
{
|
||||
// The job embeds the project: its frame positions follow frames inserted since the editor read them first. A server
|
||||
// sequence whose frames changed is outdated instead, and its toast says so and offers fresh proxies.
|
||||
await Session.EnsureFramesAsync();
|
||||
if (IsOutdated) return;
|
||||
var export = batch ? RenderExport : RenderExport with { Batch = [] };
|
||||
var requests = Session.RenderRequests(export);
|
||||
foreach (var request in requests) await Session.SubmitAsync(request with { Priority = priority });
|
||||
@@ -801,6 +810,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
|
||||
private void OnContentChanged()
|
||||
{
|
||||
// The frame on screen stays on screen, wherever frames inserted or removed before it put it (the tabs that reload
|
||||
// below may seek meanwhile).
|
||||
var shown = IndexOfFrame(_currentFrameId) ?? int.Min(CurrentIndex, int.Max(0, FrameCount - 1));
|
||||
_renderer = new PreviewRenderer(Session.Content, Session.Source);
|
||||
Planner = new ExportPlanner(Session.Content, _encoders, _host);
|
||||
if (Thumbnails.Count != FrameCount) Thumbnails = new EditorThumbnails(Session.Source, FrameCount);
|
||||
@@ -808,13 +820,27 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
foreach (var tab in Tabs) tab.OnContentChanged();
|
||||
OnPropertyChanged(nameof(Summary));
|
||||
OnPropertyChanged(nameof(FrameCount));
|
||||
CurrentIndex = int.Min(CurrentIndex, int.Max(0, FrameCount - 1));
|
||||
CurrentIndex = shown;
|
||||
UpdateMarkers();
|
||||
RequestCorrections();
|
||||
RequestPlan();
|
||||
RequestPreview(immediate: true);
|
||||
}
|
||||
|
||||
/// <summary>The id of frame <paramref name="index"/>; empty when there is none.</summary>
|
||||
private Guid FrameId(int index) => (uint)index < (uint)FrameCount ? Session.Content.Frames[index].Id : Guid.Empty;
|
||||
|
||||
/// <summary>Where frame <paramref name="id"/> is now; null when the sequence no longer has it.</summary>
|
||||
private int? IndexOfFrame(Guid id)
|
||||
{
|
||||
var frames = Session.Content.Frames;
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
if (frames[i].Id == id) return i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The UI language changed: what the tabs keep in objects (chart legends and summaries, the Auto chips of the
|
||||
/// settings), the timeline markers and the preview's info line are made again in the new language.
|
||||
|
||||
Reference in new issue
Block a user