Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

[PIXI.SPINE] Problem with unloading spine2d assets.

$
0
0

Hello,

When I switch from battle system I try to unloadAll Assets. My code seems to destroy all textures the one's from spine2d, mp4, png. For some reason spine2d assets are still in garbage resulting in having 2.3gb of ram usage instead of aroung 500mb when only UI is loaded. My code works for sure for other assets, as when menu is loaded it takes about 550mb of ram and when unloaded all assets it goes down to 250mb.Spine2d assets for menu are still there as game at start takes 150mb of ram.

 

// inside function that is triggered on back button click
destroyContainer(battlePrepareContainer, true);
unloadAssets(_.flatten([(Object.values(firstToLoad)), (Object.values(transitions))]));


export const destroyContainer = (containerName: Container | string, full = false) => {
    const destroyOptions = {
        children: true,
        texture: full,
        baseTexture: full,
    };

    const destroySpine = (spine: Spine) => {
        spine.spineDebug.debugGroup.destroy(destroyOptions);
        spine.spineDebug = null;

        spine.removeAllListeners();
        spine.parent.removeChild(spine);
        if (spinePool.has(spine.name)) {
            spinePool.delete(spine.name)
        }

        console.log('spine', spine);

        spine.destroy(destroyOptions);
        spine = null;
    };

    const destroyChildrenRecursive = (container: Container) => {
        container.children.forEach((child) => {
            if (child instanceof Spine) {
                destroySpine(child);
            } else if (child instanceof Container) {
                destroyChildrenRecursive(child);
            } else {
                child.removeAllListeners();

                child.destroy(destroyOptions);
                child = null;
            }
        });
    };

    const destroyContainerAndChildren = (container: Container) => {
        destroyChildrenRecursive(container);

        container.removeAllListeners();

        container.destroy(destroyOptions);

        container = null;
    };

    if (typeof containerName === 'string') {
        if (window[containerName] && window[containerName] instanceof Container) {
            destroyContainerAndChildren(window[containerName]);
            window[containerName] = undefined;
        }
    } else if (containerName instanceof Container) {
        destroyContainerAndChildren(containerName);
    }
};

export const unloadAssets = (exceptions: loadObject[]) => {
    const cacheKeys: string[] = Array.from(Assets.cache['_cacheMap'].keys());
    const exceptionNames = exceptions.map((exception) => exception.name);

    const menuKeys = cacheKeys.filter((key: string) => {
        if (!key.includes('common') && !key.includes('assets/') && !exceptionNames.includes(key)) {
            return true;
        }
        return false;
    });

    void Assets.unload(menuKeys)
}

Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>