Calling CCSpriteFrameCache#removeUnusedSpriteFrames can be hazardous to your apps health
I assume you already are aware of this because I see the general comments about needing to refractor the sprite framecache.
The bug is that if you call removeUnusedSpriteFrames it will remove the sprite frames but not update the _loadedFilenames cache in the CCSpriteFrameCache. Then when you go to reload one of those frames, it thinks its already loaded and will eventually return a nil sprite frame.
If you have two scenes (A & B) using two different sprite sheets and then you do the following, you will get crashes and errors in CCAnimationManager because SpriteFrames don't exist, for example:
- Load scene A using sprite sheet A
- navigate to scene B using sprite sheet B
- ! Call removeUnusedSpriteFrames. Sprites from sprite sheet A are unloaded
- navigate to scene A. The call to spriteFrameByName will call addSpriteFramesWithFile which will not reload the sprite sheet A because the file is still in the _loadedFilenames cache.
I didn't know about that one, but that's not the only bug like it. :-\ I'm not really certain how to fix many of them without changing (breaking) the API. This one sounds pretty fixable though.
Hmm. I suppose you could try to fix it - or maybe its just not used that often. I found the culprit in some 2+ year old library code so perhaps it would be easy to just deprecate that method or make it private and see how often others are using it.