Skip to content

Fix a memory leak when calling setMultiDraw #8345

@AlexAPPi

Description

@AlexAPPi

I noticed a memory leak when calling setMultiDraw several times in a row.
Allocate is always called, which results in the creation of a StorageBuffer while the previous buffer is not deleted.

cmd.allocate(maxCount);

this.storage = new StorageBuffer(this.device, this.gpuIndirect.byteLength, BUFFERUSAGE_INDIRECT | BUFFERUSAGE_COPY_DST);

It would also be good if old data was saved and not reset then allocate.

    /**
     * Allocate AoS buffer and backing storage buffer.
     * @param {number} maxCount - Number of sub-draws.
     */
    allocate(maxCount) {
        this.storage?.destroy(); // <--- DISPOSE EXISTS
        this.gpuIndirect = new Uint32Array(5 * maxCount);
        this.gpuIndirectSigned = new Int32Array(this.gpuIndirect.buffer);
        this.storage = new StorageBuffer(this.device, this.gpuIndirect.byteLength, BUFFERUSAGE_INDIRECT | BUFFERUSAGE_COPY_DST);
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions