Skip to content

Commit beed30b

Browse files
committed
Fix 0x8001010E Exception on ImageBackgroundManager.CanOpenCropOverlay
1 parent dd6f624 commit beed30b

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

CollapseLauncher/Classes/GameManagement/ImageBackground/ImageBackgroundManager.ImageCropperAndConvert.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,39 @@ void SetImageCropperProperties(ImageCropper element)
192192
}
193193
}
194194

195-
private static async Task<bool> CanOpenCropOverlay(Uri imagePath, bool isSvg, ImageCropper cropper, CancellationToken token)
195+
private static Task<bool> CanOpenCropOverlay(Uri imagePath, bool isSvg, ImageCropper cropper, CancellationToken token)
196196
{
197197
if (isSvg)
198198
{
199199
// SVG has no fixed source pixel size before rasterization, so keep existing behavior.
200-
return true;
200+
return Task.FromResult(true);
201201
}
202202

203-
WriteableBitmap sourceBitmap = new(1, 1);
204-
await using Stream sourceStream = await OpenStreamFromFileOrUrl(imagePath, token);
205-
using IRandomAccessStream randomStream = sourceStream.AsRandomAccessStream(true);
206-
await sourceBitmap.SetSourceAsync(randomStream);
203+
TaskCompletionSource<bool> tcs = new();
204+
DispatcherQueueExtensions.CurrentDispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, Impl);
205+
return tcs.Task;
206+
207+
async void Impl()
208+
{
209+
try
210+
{
211+
await using Stream sourceStream = await OpenStreamFromFileOrUrl(imagePath, token);
212+
using IRandomAccessStream randomStream = sourceStream.AsRandomAccessStream(true);
213+
214+
WriteableBitmap sourceBitmap = new(1, 1);
215+
await sourceBitmap.SetSourceAsync(randomStream);
207216

208-
return cropper.CanCropSource(sourceBitmap.PixelWidth, sourceBitmap.PixelHeight);
217+
tcs.SetResult(cropper.CanCropSource(sourceBitmap.PixelWidth, sourceBitmap.PixelHeight));
218+
}
219+
catch (OperationCanceledException)
220+
{
221+
tcs.SetCanceled(token);
222+
}
223+
catch (Exception ex)
224+
{
225+
tcs.SetException(ex);
226+
}
227+
}
209228
}
210229

211230
/// <summary>

0 commit comments

Comments
 (0)