Skip to content

Add cc.textureCache.addImageAsync API to ensure API consistency #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pandamicro opened this issue Mar 4, 2015 · 10 comments
Closed

Add cc.textureCache.addImageAsync API to ensure API consistency #1507

pandamicro opened this issue Mar 4, 2015 · 10 comments
Milestone

Comments

@pandamicro
Copy link
Contributor

For the web engine, cc.textureCache.addImage is always asynchronous, so we have merged addImage and addImageAsync API. But it turns out the difference of addImage and addImageAsync cannot be ignored.

So it's better to do the following:

  1. [Web Engine] Add addImageAsync API which is equivalent to addImage
  2. [Native Engine] Change the current addImage binding to addImageAsync, then expose the original synchronous addImage API
pandamicro added a commit to pandamicro/cocos2d-js that referenced this issue Mar 4, 2015
pandamicro added a commit that referenced this issue Mar 4, 2015
#1507: [JSB] Refactor addImageAsync to support remote image loading
@pandamicro pandamicro added this to the v3.4 milestone Mar 4, 2015
@pandamicro pandamicro reopened this Mar 9, 2015
@dingpinglv
Copy link
Contributor

The addImageAsync has been added to cc.textureCache on Web engine at: cocos2d/cocos2d-html5#2722

@0xJimmyBeh
Copy link

@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);
    }

@pandamicro
Copy link
Contributor Author

Thank you, I reproduced an issue, was the crash you met triggered by the following line ?

    JSAutoCompartment ac(_cx, _obj.ref() ? _obj.ref() : global);

@0xJimmyBeh
Copy link

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?

@pandamicro
Copy link
Contributor Author

I think the problem is due to thread & curl & Spidermonkey, I will try to find a more reliable solution

@0xJimmyBeh
Copy link

ok, thanks.

@Deviller
Copy link

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?

@0xJimmyBeh
Copy link

@Deviller

Thanks for your report on the problem.
I opened an issue about this problem at here

#1658

@pandamicro have you found any solution?

Thanks.

@zhaijialong
Copy link
Contributor

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);

@pandamicro
Copy link
Contributor Author

Yes, it's caused by another thread invoking JS API. I will try Scheduler::performFunctionInCocosThread solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants