Skip to content

Commit

Permalink
Only throw out of memory exception when onProgress is not set.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Feb 5, 2024
1 parent 1ffc5db commit a871c4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/magick-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TReturnType>(func: (image: IMagickImage) => TReturnType): TReturnType;
/** @internal */
Expand Down
10 changes: 6 additions & 4 deletions src/native-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down

0 comments on commit a871c4c

Please sign in to comment.