Skip to content

Commit

Permalink
fix: destroy clone obj caused imgclip throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed May 27, 2024
1 parent d611437 commit 30846b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/av-cliper/src/clips/__tests__/img-clip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ test('split by time', async () => {
preClip.meta.duration + postClip.meta.duration,
);
});

test('clone ImgClip', async () => {
const clip = new ImgClip((await fetch(static_jpg)).body!);
const cloneClip = await clip.clone();
clip.destroy();
const { state } = await cloneClip.tick(10e6);
expect(state).toBe('success');
});
8 changes: 5 additions & 3 deletions packages/av-cliper/src/clips/img-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ export class ImgClip implements IClip {

async clone() {
await this.ready;
return new ImgClip(
this.#img ?? this.#frames.map((vf) => vf.clone()),
) as this;
const data =
this.#img == null
? this.#frames.map((vf) => vf.clone())
: await createImageBitmap(this.#img);
return new ImgClip(data) as this;
}

destroy(): void {
Expand Down

0 comments on commit 30846b8

Please sign in to comment.