Skip to content

Commit 32f517c

Browse files
kohakukunkainino0x
andauthored
WebGPU: fix memory leak when calling destroy on a buffer (#18790)
- Call custom emscripten `onUnmap` callbacks also when calling destroy on a buffer. Co-authored-by: Kai Ninomiya <kainino@chromium.org>
1 parent db51a47 commit 32f517c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/library_webgpu.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,18 @@ var LibraryWebGPU = {
674674

675675
// *Destroy
676676

677-
wgpuBufferDestroy: function(bufferId) { WebGPU.mgrBuffer.get(bufferId)["destroy"](); },
677+
wgpuBufferDestroy: function(bufferId) {
678+
var bufferWrapper = WebGPU.mgrBuffer.objects[bufferId];
679+
{{{ gpu.makeCheckDefined('bufferWrapper') }}}
680+
if (bufferWrapper.onUnmap) {
681+
for (var i = 0; i < bufferWrapper.onUnmap.length; ++i) {
682+
bufferWrapper.onUnmap[i]();
683+
}
684+
bufferWrapper.onUnmap = undefined;
685+
}
686+
687+
WebGPU.mgrBuffer.get(bufferId)["destroy"]();
688+
},
678689
wgpuTextureDestroy: function(textureId) { WebGPU.mgrTexture.get(textureId)["destroy"](); },
679690
wgpuQuerySetDestroy: function(querySetId) { WebGPU.mgrQuerySet.get(querySetId)["destroy"](); },
680691

0 commit comments

Comments
 (0)