Join GitHub today
CCLoader error when preload resource twice #576
If you preload resources at runtime and you happen to preload a resource twice, the loader ends up in an infinite loop.
when later using cc.Loader.shareLoader().preload(res) , loadedResourceCount will be higher than resourceCount, so the isLoadedComplete never triggers the onLoad
Or am I doing something wrong?
The cc.Loader.shareLoader().preload(res) should be called before game runs. It is not allowed to call cc.TextureCache.getInstance().addImage() before preload all resources.
BTW, the preloading will be modified to support multi scene loading before next release. So the resources can be loaded by several times, and it will speed up the first time game play.
Thanks for the reply.
I use ajax to change my site's content, so I never get a "full page refresh". Because of that I was reusing my application and came in the situation where I had previously preloaded resources and wanting to preload some other resources.
See it as a selection-screen for two games which are both cc.Scenes. I did not want to preload the resources of the scene before the user actually selected that game. I guess that the modification you mentioned will solve this problem.
Now I created a workaround where I "unload" the whole application, removing the canvas, clearing cc, etc. when I leave a game. When selecting a new game everything of cocos is initialized as if new. The "unloading" is still a bit messy, but I did not know how to unload cocos without an actual page refresh. Now I do the following: