#gpu.js memory leak and other .

2 messages · Page 1 of 1 (latest)

candid cypress
#

Hi , recently i tried to use gpu.js and ive done some testing . i have a lot of data to send to gpu.js to use a graphical shader. what ive done is 3 thing . first get all my list of entity to draw. then ive flattened the list into a 1d array and created a single 1d array representing some sort of texture in a way. and finnally ive encoded my color into a bitwise system. now all of that is working but i seem to have huge memory leak . my gpu memory is growing infinetely. ive fairly new to gpu.js and i was wondering if someone could help me on this subject . my other problem which might very well be related is that . without drawing anythng im always 60+ fps but now with this im 40 fps and going down. here's are the 4 script ```js
function flattenEntities(entities) {
const flattenedArray = [];

entities.forEach((entity) => {
    if (entity.type === "bulb") {
        const { position, Color } = entity;
        flattenedArray.push([floor(position.x), floor(position.y), red(Color), green(Color), blue(Color)]);
    } else if (entity.type === "creature") {
        entity.parts.body.forEach((part) => {
            const { position, color } = part;
            flattenedArray.push([floor(position.x + entity.position.x), floor(position.y + entity.position.y), red(color), green(color), blue(color)]);
        });
    }
});

return flattenedArray;

}

#
function create1DArray(flattenedArray, sizeX, sizeY) {
    if (!FullArrayForGraphic) {
        FullArrayForGraphic = new Array(sizeX * sizeY).fill(1);
    }

    for (let value of modifiedIndices) {
        FullArrayForGraphic[value] = 1;
    }

    modifiedIndices.clear();

    for (const entity of flattenedArray) {
        const [x, y, ...rest] = entity;
        const index = y * sizeX + x;


        FullArrayForGraphic[index] = encodeEntity(entity[2], entity[3], entity[4]);
        modifiedIndices.add(index);
    }
}

function encodeEntity(colorR, colorG, colorB) {
    const maxColor = 255;

    const red = Math.max(0, Math.min(colorR, maxColor));
    const green = Math.max(0, Math.min(colorG, maxColor));
    const blue = Math.max(0, Math.min(colorB, maxColor));


    const encodedValue = (red << 16) | (green << 8) | blue;

    return encodedValue;
}