Plist problem after 2.2 migration

I have upgraded my version of cocos2d to 2.2 (I am using the .min.js file).
after upgrading the addSpriteFrames method seem to stopped working like it did.
I have this
var cache = cc.SpriteFrameCache.getInstance();
cache.addSpriteFrames("spriteSheets/aSpriteSheet.plist","spriteSheets/aSpriteSheet.png");
and I get an error:
Uncaught cocos2d: spriteSheets/aSpriteSheet.plist is not a plist file
The error will pop for any plist file I try to load to the cache.
the same code worked perfect with version 2.1.5.
How can I fix this?

Hi,
Did you try to run our testcases on your computer? Does the SpriteTest work well?

And the “spriteSheets/aSpriteSheet.plist is not a plist file” shows only when the xmlDocument’s tagName not equal “plist”. The codes as follow (CCSAXParser.js):
@ var xmlDoc = this._parserXML(textxml, path);

var plist = xmlDoc.documentElement;
if (plist.tagName != ‘plist’)
throw “cocos2d:” + path + " is not a plist file";@

I have tested our testcases using the .min.js file on my coumputer, it has been worked.

Could you please send the .min.js file and the plist to me?

Best regards
David

the test cases work.
this happens with all my plists, I generated them using Texture packer.
the .min file is the one in the download from the cocos2d site.
I attached the files you asked for.

and the plist file

Hi,

I have tested your min.js and girlSheet1.plist in my hello world app, it works well.

Could you please send a demo app to my email? let me reproduce the problem, my email address is dingping.lv@cocos2d-x.org.

Thank you.

It is suggested that you could provide a small zip file to reproduce the issue.

Hi,
So I’ve tried to build a small project that reproduced the issue but I can’t seem to pin it. I have a working solution for my project that I will elaborate here, but the weird thing is that the issue disappear if I revert to using the older cocos2d.
I’m building a project that has a big set of assets so I divided my resources and I only load the assets I need for the running scene. it looks something like that
@
c.Loader.preload(Progress.getNextSceneDataTags(), function () {
MyAnimationLoader (Progress.getNextScene());
var scene = cc.BuilderReader.load(“nextScene.ccbi”);
cc.Director.getInstance().replaceScene(scene);
}, this);@
so Progress object tells me where the game stands and I load the correct res for it. after it loads I use MyAnimationLoader, an object that calls addSpriteFrames and creates animation according to the game state I give it.
for some reason this stopped working in some cases after the upgrade. it is as if the cc.Loader is calling the function before it really loaded the assets and the program can’t find the assets for the scene.
for now I just load the assets in a earlier stage but this is suboptimal, and also just weird cause it just works fine if I use 2.1.5.

you can put “spriteSheets/aSpriteSheet.plist” in resources-html5.js, ex:
var s_aspp = "spriteSheets/aSpriteSheet.plist"; var g_resources = [ {src:s_aspp} ];

before you use it,you will load the g_resources, ex:cc.LoaderScene.preload(g_resources, function () { director.replaceScene(yourScene()); }, this);

Hi, I think I know what went wrong, so I’m being a good boy and telling you.
It’s been a while since this problem appeared and I used a work around so not sure this is it but I am pretty sure.
a similar problem suddenly appeared later on in development and from the way I see it the issue is having more then one preloader run at the same time. one preload is finished and calls the call back of the other preloader.
psaudo code:
@
load(asset1);
load(asset2,callback{ createAnim(asset2) });
@
so asset1 finishes loading and calls the callback of asset2 preloder. but since the preloading of asset2 is not done the program fails!
this didn’t happen with the older version but it night have been just a coincidence.
I still don’t have a real solution for this other then avoiding more then one preload triggering at a time. but if you need, like I do, a complex loading system and use preloadAsync, avoiding multiple calls can prove problematic.
BTW this also happened with calls to preloadEffect!

This is a problem I have at the moment. I use regular preload rather than async and have confirmed that multiple sprite sheets are not required. I have observed my plist load correctly, but then by the time it gets to the SAX parser the dict (_xmlDict) is empty. Why this happens is currently a mystery, but it does look like a race condition of some kind.

Here’s the problem, in the SAX parser getList is being called before preloadPlist has reached readyState four, so what getList gets is junk. This all happens in addSpriteFrames while it makes a call to fileUtils.dictionaryWithContentsOfFileThreadSafe(). I would be happy to submit a patch once I’ve fixed it but I am not so sure what the preferred solution would be for the project.

I think the synchronous looking interface of the sax parser probably needs to change so that it uses callbacks. Currently the code that uses the parser assumes it is synchronous, and has no way of dealing with it’s asynchronous nature anyway. So calls should probably be split up into a call to initiate the operation, and a callback on operation complete.

So this thing came back at me.
I don’t know about what pete wrote here, that aspect of the bug I had stope bothering me after I did some non-best practice stuff.
but I found one weird case- my project is build with cocosbuilder and I have massive memory handling, the code is constantly adding and throwing away assets. I have a scene build with Builder, that scene has a background image. I had it thrown away from memory in the wrong time.
after hours of looking what could lead to the “not a plist” message I noticed that the said image is being removed before the time is right, and bang the plist problem went away! the thing is the BG image was showing on screen when needed and the message did not mention it- I think it is related to the loading of the ccbi, it uses the BG image so maybe it had some reference enabling it to show the image but still causing weird behaviour.
So this Is kind of Voodoo stuff- sorry- I know it’s because I don’t understand something somewhere.
also I’m using cocos2d.min file so I’m lazy to follow this in the readable code.
I hope that it can help if you have a similar problem.

The final conclusion I have on the “not a plist bug” is that you may not ever have 2 preload processes at the same time!
not even having the call back start a new preload when the other is done. So not even some kind of pending mechanism. I’m not sure why, but that is defiantly the way it works for version 2.2
I ended up just blocking any loads from starting at the same time by using a double index- one increments when load request is made and one on call back- if they are not equal I would not let another process start.
I don’t know if this is a bug with cocos2d or if multiple preloads at a time is just to much for javascript context, just know that this is the way it is for now.

The final conclusion I have on the “not a plist bug” is that you may not ever have 2 preload processes at the same time!
not even having the call back start a new preload when the other is done. So not even some kind of pending mechanism. I’m not sure why, but that is defiantly the way it works for version 2.2
I ended up just blocking any loads from starting at the same time by using a double index- one increments when load request is made and one on call back- if they are not equal I would not let another process start.
I don’t know if this is a bug with cocos2d or if multiple preloads at a time is just to much for javascript context, just know that this is the way it is for now.

in CCSaxParser.js:
preloadPlist: function (filePath) {
filePath = cc.FileUtils.getInstance().fullPathForFilename(filePath);

That first line of the function there may be the cause of a lot of the pain - it’s missing the var, so filepath is global, two documents called close together would have that filepath be overwritten, therefore overwriting the key that is used to store the doc in the cache. Try adding the var and see if your problem goes away.

Thanks pete.
I’ll try that

the “var” is missing but this does not solve the problem

the “var” is missing but this does not solve the problem

I have submitted a path in order to solve this problem and have been merged into the developer branch.