Closed pandamicro closed 9 years ago
The addImageAsync
has been added to cc.textureCache on Web engine at: https://github.com/cocos2d/cocos2d-html5/pull/2722
@pandamicro
cc.textureCache.addImageAsync cause crashed on Android v4.4.4 with unpublished cocos2d-js v3.5 at http://www.cocos2d-x.org/filedown/cocos2d-js-v3.5.zip
working fine on Mac, iOS crashed for first time then not crash after that.
Tested with code below :
var imageUrlArray = ["http://www.cocos2d-x.org/s/upload/v35.jpg", "http://www.cocos2d-x.org/s/upload/testin.jpg", "http://www.cocos2d-x.org/s/upload/geometry_dash.jpg"];
for (var i = 0; i < imageUrlArray.length; i++)
{
cc.textureCache.addImageAsync(imageUrlArray[i], this.imageLoaded, this);
}
Thank you, I reproduced an issue, was the crash you met triggered by the following line ?
JSAutoCompartment ac(_cx, _obj.ref() ? _obj.ref() : global);
There is no error show on the console log in Cocos Code IDE 1.2.0 when debug with Android device, working fine on Mac.
Is there any setup to show the error log?
I think the problem is due to thread & curl & Spidermonkey, I will try to find a more reliable solution
ok, thanks.
I can confirm that there is some bug in the line: JSAutoCompartment ac(_cx, _obj.ref() ? _obj.ref() : global); In function __JSDownloaderDelegator::onSuccess
It crashes often on android and rarely on iOS
Do you have any fix for this?
@Deviller
Thanks for your report on the problem. I opened an issue about this problem at here
https://github.com/cocos2d/cocos2d-js/issues/1658
@pandamicro have you found any solution?
Thanks.
I think this problem is caused by thread safe. I didn't look into the code. is onSuccess
run in a new thread? If it does and invokes js api , it's not safe. Maybe we should use Scheduler::performFunctionInCocosThread
or something similar.
And another way is we use a thread safe buildt SpiderMonkey, and wrap the js api calls in a:
JS_BeginRequest(cx);
...
JS_EndRequest(cx);
Yes, it's caused by another thread invoking JS API. I will try Scheduler::performFunctionInCocosThread
solution
For the web engine,
cc.textureCache.addImage
is always asynchronous, so we have mergedaddImage
andaddImageAsync
API. But it turns out the difference ofaddImage
andaddImageAsync
cannot be ignored.So it's better to do the following:
addImageAsync
API which is equivalent toaddImage
addImage
binding toaddImageAsync
, then expose the original synchronousaddImage
API