I haven't noticed that issue in my own projects. From what I can see in the code:
void Cocos2dTextureLoader::load(AtlasPage& page, const spine::String& path) {
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path.buffer());
CCASSERT(texture != nullptr, "Invalid image");
if (texture)
{
texture->retain();
Texture2D::TexParams textureParams = { filter(page.minFilter), filter(page.magFilter), wrap(page.uWrap), wrap(page.vWrap) };
texture->setTexParameters(textureParams);
page.setRendererObject(texture);
page.width = texture->getPixelsWide();
page.height = texture->getPixelsHigh();
}
}
It's clearly using the TextureCache, since the addImage() function checks if the texture already exists, and if it does, it returns a pointer to it, otherwise it loads it and adds it to the cache.
If you preload the texture, then this should work, but you have to watch out for the value of the path
parameter, which is the key used to locate the texture in the std::unordered_map
. If it's not precisely the same, then the image will be loaded again and a new texture created for that path key.
One other thing, if after preloading, but before loading your spine models, anything calls Director::getInstance()->getTextureCache()->removeUnusedTextures();
, and retain()
was never called on the texture, then that texture will be removed if it's not being referenced anywhere else.