Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a font asset is unloaded the font’s textures are not destroyed and still consume VRAM #7033

Open
Kulodo opened this issue Oct 15, 2024 · 0 comments

Comments

@Kulodo
Copy link

Kulodo commented Oct 15, 2024

When a font asset is unloaded the font’s textures are not destroyed and still consume VRAM.
Is there a reason for that or is it a bug?

The font class does not have a destroy method so asset.unload cannot call it.

I attempted a work around in the test project https://playcanvas.com/project/1264902/overview/unloading-a-font-asset.
In this project the user can press the space bar to toggle between a large VRAM font and a small VRAM font.
To show the bug, comment out the workaround in this function.

Test.prototype.unloadFontAsset = function(fontAsset)  {
    // When unloading a font asset the font's texture(s) are not destroyed.
    // which is a waste of VRAM.
    let textures = fontAsset.resource.textures;
    for (let i = 0; i < textures.length; i++) {
        let texture = textures[i];

        // Destroy to free resources associated with this texture.
        // see https://api.playcanvas.com/classes/Engine.Texture.html#destroy
        texture.destroy();

        // Clear the font texture from the resource loader cache.
        // see https://api.playcanvas.com/classes/Engine.ResourceLoader.html#clearCache
        this.app.loader.clearCache(texture.name,'texture');
    }
    fontAsset.unload();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant