From a871c4c06416ae05b6bce73d07e5ff4ff37b498d Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 5 Feb 2024 19:18:39 +0100 Subject: [PATCH] Only throw out of memory exception when onProgress is not set. --- src/magick-image.ts | 12 ++++++++++++ src/native-instance.ts | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/magick-image.ts b/src/magick-image.ts index c2a05d2c..01bfd420 100644 --- a/src/magick-image.ts +++ b/src/magick-image.ts @@ -3008,6 +3008,18 @@ export class MagickImage extends NativeInstance implements IMagickImage { throw new MagickError('no image has been read'); } + /** @internal */ + protected _setInstance(instance: number, exception: Exception): boolean { + if (super._setInstance(instance, exception) === true) + return true; + + // Assume the task was cancelled if the instance is 0 and the progress delegate is set. + if (instance === 0 && this.onProgress !== undefined) + return true; + + throw new MagickError('out of memory'); + } + /** @internal */ _use(func: (image: IMagickImage) => TReturnType): TReturnType; /** @internal */ diff --git a/src/native-instance.ts b/src/native-instance.ts index d9a31748..1325b048 100644 --- a/src/native-instance.ts +++ b/src/native-instance.ts @@ -42,15 +42,17 @@ export abstract class NativeInstance { } /** @internal */ - protected _setInstance(instance: number, exception: Exception): void { - exception.check(() => { - if (instance == 0) - throw new MagickError('out of memory'); + protected _setInstance(instance: number, exception: Exception): boolean { + return exception.check(() => { + if (this.instance === 0) + return false; this.dispose(); this.instance = instance; + return true; }, () => { this.disposeInstance(instance); + return true; }); }