Skip to content

Commit b079705

Browse files
committed
Merge pull request cocos2d#14702 from pandamicro/v3.10
Fix Downloader callback bug on iOS9
2 parents 2881ce7 + 58902f0 commit b079705

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

cocos/2d/CCFontFNT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ void FontFNT::reloadBMFontResource(const std::string& fntFilePath)
821821
if (ret)
822822
{
823823
s_configurations->insert(fntFilePath, ret);
824-
TextureCache::getInstance()->reloadTexture(ret->getAtlasName());
824+
Director::getInstance()->getTextureCache()->reloadTexture(ret->getAtlasName());
825825

826826
}
827827
}

cocos/3d/CCSprite3D.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
364364
{
365365
sprite->setName(nodedata->id);
366366
auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
367+
368+
if (_skeleton && modeldata->bones.size())
369+
{
370+
auto skin = MeshSkin::create(_skeleton, modeldata->bones, modeldata->invBindPose);
371+
mesh->setSkin(skin);
372+
}
373+
367374
if (modeldata->matrialId == "" && materialdatas.materials.size())
368375
{
369376
const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
@@ -748,7 +755,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
748755
{
749756
#if CC_USE_CULLING
750757
// camera clipping
751-
if(Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&this->getAABB()))
758+
if(_children.size() == 0 && Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&getAABB()))
752759
return;
753760
#endif
754761

cocos/network/CCDownloader-apple.mm

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
#include "network/CCDownloader-apple.h"
2626

2727
#include "network/CCDownloader.h"
28+
#include "CCString.h"
2829
#include <queue>
2930

3031
////////////////////////////////////////////////////////////////////////////////
@@ -388,32 +389,50 @@ - (void)URLSession:(NSURLSession *)session task :(NSURLSessionTask *)task
388389

389390
if(_outer)
390391
{
391-
if(error) {
392+
if(error)
393+
{
392394
std::vector<unsigned char> buf; // just a placeholder
393395
_outer->onTaskFinish(*[wrapper get],
394396
cocos2d::network::DownloadTask::ERROR_IMPL_INTERNAL,
395397
(int)error.code,
396398
[error.localizedDescription cStringUsingEncoding:NSUTF8StringEncoding],
397399
buf);
398400
}
399-
else if(![wrapper get]->storagePath.length()) {
401+
else if (![wrapper get]->storagePath.length())
402+
{
400403
// call onTaskFinish for a data task
401404
// (for a file download task, callback is called in didFinishDownloadingToURL)
402405
std::string errorString;
403-
406+
404407
const int64_t buflen = [wrapper totalBytesReceived];
405408
char buf[buflen];
406-
407409
[wrapper transferDataToBuffer:buf lengthOfBuffer:buflen];
408-
409410
std::vector<unsigned char> data(buf, buf + buflen);
410411

411412
_outer->onTaskFinish(*[wrapper get],
412413
cocos2d::network::DownloadTask::ERROR_NO_ERROR,
413-
0,
414+
0,
414415
errorString,
415416
data);
416417
}
418+
else
419+
{
420+
NSInteger statusCode = ((NSHTTPURLResponse*)task.response).statusCode;
421+
422+
// Check for error status code
423+
if (statusCode >= 400)
424+
{
425+
std::vector<unsigned char> buf; // just a placeholder
426+
const char *orignalURL = [task.originalRequest.URL.absoluteString cStringUsingEncoding:NSUTF8StringEncoding];
427+
std::string errorMessage = cocos2d::StringUtils::format("Downloader: Failed to download %s with status code (%d)", orignalURL, (int)statusCode);
428+
429+
_outer->onTaskFinish(*[wrapper get],
430+
cocos2d::network::DownloadTask::ERROR_IMPL_INTERNAL,
431+
0,
432+
errorMessage,
433+
buf);
434+
}
435+
}
417436
}
418437
[self.taskDict removeObjectForKey:task];
419438
[wrapper release];
@@ -510,12 +529,21 @@ - (void)URLSession:(NSURLSession *)session downloadTask :(NSURLSessionDownloadTa
510529
return;
511530
}
512531

532+
// On iOS 9 a response with status code 4xx(Client Error) or 5xx(Server Error)
533+
// might end up calling this delegate method, saving the error message to the storage path
534+
// and treating this download task as a successful one, so we need to check the status code here
535+
NSInteger statusCode = ((NSHTTPURLResponse*)downloadTask.response).statusCode;
536+
if (statusCode >= 400)
537+
{
538+
return;
539+
}
540+
513541
DownloadTaskWrapper *wrapper = [self.taskDict objectForKey:downloadTask];
514542
const char * storagePath = [wrapper get]->storagePath.c_str();
515543
NSString *destPath = [NSString stringWithUTF8String:storagePath];
516544
NSFileManager *fileManager = [NSFileManager defaultManager];
517545
NSURL *destURL = nil;
518-
546+
519547
do
520548
{
521549
if ([destPath hasPrefix:@"file://"])

tests/cpp-tests/Classes/DownloaderTest/DownloaderTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ static const char* sURLList[] =
3636
{
3737
"http://www.cocos2d-x.org/attachments/802/cocos2dx_landscape.png",
3838
"http://www.cocos2d-x.org/docs/manual/framework/native/wiki/logo-resources-of-cocos2d-x/res/2dx_icon_512_rounded.png",
39-
"http://www.cocos2d-x.org/attachments/1503/Cocos2CoordinateRelease.png",
39+
"http://www.cocos2d-x.org/attachments/1503/inexist.png",
4040
"http://download.sdkbox.com/installer/v1/sdkbox-iap_v1.2.3.3.tar.gz",
4141
};
4242
const static int sListSize = (sizeof(sURLList)/sizeof(sURLList[0]));
4343
static const char* sNameList[sListSize] =
4444
{
4545
"cocos2dx_landscape.png",
4646
"2dx_icon_512_rounded.png",
47-
"Cocos2CoordinateRelease.png",
47+
"inexist file",
4848
"big file",
4949
};
5050

@@ -112,6 +112,7 @@ struct DownloaderTest : public TestCase
112112
label->setPosition(Vec2(viewSize.width / 2, viewSize.height / 2));
113113
label->setContentSize(Size(viewSize.width, 0));
114114
label->setAlignment(TextHAlignment::CENTER, TextVAlignment::CENTER);
115+
label->setDimensions(viewSize.width, viewSize.height);
115116
bg->addChild(label, 20);
116117

117118
return bg;

tests/cpp-tests/proj.ios/Info.plist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
<false/>
99
<key>NSExceptionDomains</key>
1010
<dict>
11+
<key>sdkbox.com</key>
12+
<dict>
13+
<key>NSIncludesSubdomains</key>
14+
<true/>
15+
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
16+
<true/>
17+
<key>NSTemporaryExceptionMinimumTLSVersion</key>
18+
<string>TLSv1.1</string>
19+
</dict>
1120
<key>cocos2d-x.org</key>
1221
<dict>
1322
<key>NSIncludesSubdomains</key>

tests/js-tests/src/TextureCacheTest/TextureCacheTest.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ var RemoteTextureTest = TextureCacheTestBase.extend({
282282
for (var i = 0; i < imageUrlArray.length; i++) {
283283
cc.textureCache.addImageAsync(imageUrlArray[i], this.texLoaded, this);
284284
}
285+
286+
cc.loader.loadImg("http://www.cocos2d-x.org/no_such_file.jpg", this.failLoaded.bind(this));
285287
},
286288

287289
texLoaded: function(texture) {
@@ -296,6 +298,21 @@ var RemoteTextureTest = TextureCacheTestBase.extend({
296298
else {
297299
cc.log("Fail to load remote texture");
298300
}
301+
},
302+
303+
failLoaded: function (err, img) {
304+
var str = "";
305+
if (err) {
306+
str = "Correct behavior: failed to download from wrong url";
307+
}
308+
else {
309+
str = "!!! Wrong behavior: succeed to download from wrong url";
310+
}
311+
312+
var label = new cc.LabelTTF(str, "Times New Roman", 28);
313+
label.x = winSize.width / 2;
314+
label.y = winSize.height / 2;
315+
this.addChild(label, 100);
299316
}
300317
});
301318

0 commit comments

Comments
 (0)