Skip to content

Commit

Permalink
fix: buffer not released when modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed May 14, 2024
1 parent 32751c0 commit dbfce5a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 48 deletions.
55 changes: 11 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,17 @@
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": "./dist/core/index.js",
"types": "./dist/core/index.d.ts"
},
"./cache-buster": {
"import": "./dist/cache-buster/index.js",
"types": "./dist/cache-buster/index.d.ts"
},
"./cli": {
"import": "./dist/cli/index.js",
"types": "./dist/cli/index.d.ts"
},
"./ffmpeg": {
"import": "./dist/ffmpeg/index.js",
"types": "./dist/ffmpeg/index.d.ts"
},
"./image": {
"import": "./dist/image/index.js",
"types": "./dist/image/index.d.ts"
},
"./json": {
"import": "./dist/json/index.js",
"types": "./dist/json/index.d.ts"
},
"./manifest": {
"import": "./dist/manifest/index.js",
"types": "./dist/manifest/index.d.ts"
},
"./pixi": {
"import": "./dist/pixi/index.js",
"types": "./dist/pixi/index.d.ts"
},
"./spine": {
"import": "./dist/spine/index.js",
"types": "./dist/spine/index.d.ts"
},
"./texture-packer": {
"import": "./dist/texture-packer/index.js",
"types": "./dist/texture-packer/index.d.ts"
},
"./webfont": {
"import": "./dist/webfont/index.js",
"types": "./dist/webfont/index.d.ts"
}
".": "./dist/core/index.js",
"./cache-buster": "./dist/cache-buster/index.js",
"./cli": "./dist/cli/index.js",
"./ffmpeg": "./dist/ffmpeg/index.js",
"./image": "./dist/image/index.js",
"./json": "./dist/json/index.js",
"./manifest": "./dist/manifest/index.js",
"./pixi": "./dist/pixi/index.js",
"./spine": "./dist/spine/index.js",
"./texture-packer": "./dist/texture-packer/index.js",
"./webfont": "./dist/webfont/index.js"
},
"main": "dist/core/index.js",
"module": "dist/core/index.js",
Expand Down
12 changes: 12 additions & 0 deletions src/core/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,17 @@ export class Asset
this.transformChildren[i].releaseBuffers();
}
}

/**
* Release all buffers from this asset and its children
*/
releaseChildrenBuffers()
{
this.releaseBuffers();
for (let i = 0; i < this.children.length; i++)
{
this.children[i].releaseChildrenBuffers();
}
}
}

3 changes: 3 additions & 0 deletions src/core/AssetPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export class AssetPack
// write back to the cache...
await (assetCache as AssetCache).write(root);

// release the buffers from the cache
root.releaseChildrenBuffers();

Logger.info('cache updated.');
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/pipes/PipeSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ export class PipeSystem
async transform(asset: Asset): Promise<void>
{
await this._transform(asset, 0);

// clean up any buffers still held for gc!
asset.releaseBuffers();
}

private async _transform(asset: Asset, pipeIndex = 0): Promise<void>
Expand Down
4 changes: 3 additions & 1 deletion test/core/Assetpack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Core', () =>
const assetpack = new AssetPack({
entry: inputDir, cacheLocation: getCacheDir(pkg, testName),
output: outputDir,
cache: false,
cache: true,
});

await assetpack.watch();
Expand All @@ -109,6 +109,7 @@ describe('Core', () =>

expect(existsSync(join(outputDir, 'new-json-file.json'))).toBe(true);
expect(existsSync(join(outputDir, 'json.json'))).toBe(true);
fs.writeJSONSync(join(inputDir, 'json.json'), { nice: 'test' });

fs.removeSync(testFile);

Expand All @@ -121,6 +122,7 @@ describe('Core', () =>

expect(existsSync(join(outputDir, 'new-json-file.json'))).toBe(false);
expect(existsSync(join(outputDir, 'json.json'))).toBe(true);
expect(fs.readJSONSync(join(outputDir, 'json.json'))).toStrictEqual({ nice: 'test' });
});

it('should ignore specified files when watching', async () =>
Expand Down

0 comments on commit dbfce5a

Please sign in to comment.