Repeated run-time bake adds to VRAM


#1

Hello,

In my application, when I move to a location in the Map of the environment, I load the location and it’s assets and call app.lightmapper.bake to the loaded assets.

When I move to a new location in the Map, I destroy the associated textures of the current location of the environment, before I load the new locations asset, textures and call the lightmapper.bake on the new location’s assets.

now as I alternate between these two locations, the lightmap VRAM keeps increasing. Is there a destroy function to undo the bake of location assets, once I leave that location, similar to the destroy function I perform on asset material textures.

I run into the issue of the game crashing eventually, after the 4th alteration between the 2 locations because the VRAM increases each alteration until the device can’t handle it anymore

  • Thanks

#2

Looking at the source code of the Lightmapper class it seems that each call on bake() already does that.

I would say try stepping the code through the debugger to see if it works as intended.

            if (!nodes) {
                // ///// Full bake /////

                // delete old lightmaps, if present
                for (i = 0; i < sceneLightmaps.length; i++) {
                    for (j = 0; j < sceneLightmaps[i].length; j++) {
                        sceneLightmaps[i][j].destroy();
                    }
                }
                sceneLightmaps = [];
                sceneLightmapsNode = [];

                // collect
                nodes = [];
                collectModels(this.root, nodes, nodesMeshInstances, allNodes);
            } else {
                // ///// Selected bake /////

                // delete old lightmaps, if present
                var k;
                for (i = sceneLightmapsNode.length - 1; i >= 0; i--) {
                    for (j = 0; j < nodes.length; j++) {
                        if (sceneLightmapsNode[i] === nodes[j]) {
                            for (k = 0; k < sceneLightmaps[i].length; k++) {
                                sceneLightmaps[i][k].destroy();
                            }
                            sceneLightmaps.splice(i, 1);
                            sceneLightmapsNode.splice(i, 1);
                        }
                    }
                }

                // collect
                var _nodes = [];
                for (i = 0; i < nodes.length; i++) {
                    collectModels(nodes[i], _nodes, nodesMeshInstances);
                }
                nodes = _nodes;

                collectModels(this.root, null, null, allNodes);
            }

#3

Interesting, I’ll take a close look then, thanks