Skip to content

Commit 1f13aa6

Browse files
committed
Fix PDF thumbnail rendering crash #1531
1 parent 72c8e56 commit 1f13aa6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

QuickLook.Plugin/QuickLook.Plugin.PDFViewer/AsyncPageToThumbnailConverter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System;
1919
using System.Globalization;
2020
using System.Threading.Tasks;
21+
using System.Windows.Controls;
2122
using System.Windows.Data;
2223
using System.Windows.Media.Imaging;
2324

@@ -30,19 +31,25 @@ internal class AsyncPageToThumbnailConverter : IMultiValueConverter
3031

3132
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
3233
{
33-
if (values.Length < 2)
34+
if (values.Length < 3)
3435
throw new Exception("PageIdToImageConverter");
3536

3637
if (values[0] is not PdfDocumentWrapper handle) return null;
3738

3839
var pageId = (int)values[1];
3940
if (pageId < 0) return null;
4041

42+
if (values[2] is not UserControl thisPdfViewer) return null;
43+
4144
var task = Task.Run(() =>
4245
{
4346
try
4447
{
45-
return handle.RenderThumbnail(pageId);
48+
if (handle is null || thisPdfViewer is null) return Loading;
49+
return thisPdfViewer.Dispatcher.Invoke(() =>
50+
{
51+
return handle.RenderThumbnail(pageId);
52+
});
4653
}
4754
catch (Exception)
4855
{

QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<MultiBinding Converter="{StaticResource AsyncPageToThumbnailConverter}">
6363
<Binding ElementName="thisPdfViewer" Path="PdfDocumentWrapper" />
6464
<Binding />
65+
<Binding ElementName="thisPdfViewer" />
6566
</MultiBinding>
6667
</Image.DataContext>
6768
</Image>

0 commit comments

Comments
 (0)