Skip to content

Commit 965d744

Browse files
authored
[LottieViewer] PixelView bug fixed. We should not update pixel view when it is not on the screen. (#475)
1 parent 6d34478 commit 965d744

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

LottieViewer/MainPage.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ void ControlPanelButtonChecked(object sender, RoutedEventArgs e)
421421
ControlPanel.Children.Add(ColorPanel);
422422
}
423423

424+
// PixelView should be active only when Info page is open.
425+
// Otherwise changing surface that is not yet on the screen
426+
// will throw an exception.
427+
_pixelView.Active = sender == InfoButton;
428+
424429
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsControlPanelVisible)));
425430
}
426431

@@ -433,6 +438,11 @@ void ControlPanelButtonUnchecked(object sender, RoutedEventArgs e)
433438
// trigger the PaneThemeTransition so that the pane slides in and out.
434439
ControlPanel.Children.Clear();
435440

441+
// PixelView should be active only when Info page is open.
442+
// Otherwise changing surface that is not yet on the screen
443+
// will throw an exception.
444+
_pixelView.Active = false;
445+
436446
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsControlPanelVisible)));
437447
}
438448

LottieViewer/PixelViewElement.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public sealed class PixelViewElement : UserControl
3333
readonly SpriteVisual _spriteVisual;
3434
Visual? _capturedVisual = null;
3535

36+
// Indicates if PixelView should update the image.
37+
public bool Active { get; set; } = false;
38+
3639
// Checkerboard pattern bitmap.
3740
static CanvasBitmap? _patternBitmap = null;
3841

@@ -171,10 +174,13 @@ async Task ShowBitmapOnTargetAsync(CanvasBitmap bitmap)
171174

172175
void OnFrameArrived(Direct3D11CaptureFramePool sender, object args)
173176
{
174-
using (var frame = sender.TryGetNextFrame())
177+
if (Active)
175178
{
176-
CanvasBitmap bitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice!, frame.Surface);
177-
_ = ShowBitmapOnTargetAsync(bitmap);
179+
using (var frame = sender.TryGetNextFrame())
180+
{
181+
CanvasBitmap bitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice!, frame.Surface);
182+
_ = ShowBitmapOnTargetAsync(bitmap);
183+
}
178184
}
179185
}
180186

0 commit comments

Comments
 (0)