Merge pull request #13189 from pandamicro/v3

Fix AssetsManager crash by protecting Downloader with shared_ptr
This commit is contained in:
pandamicro 2015-08-04 15:07:23 +08:00
commit 276933c2ac
3 changed files with 5 additions and 3 deletions

View File

@ -39,8 +39,7 @@ int Device::getDPI()
NSScreen *screen = [NSScreen mainScreen]; NSScreen *screen = [NSScreen mainScreen];
NSDictionary *description = [screen deviceDescription]; NSDictionary *description = [screen deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize( CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f); return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f);
} }

View File

@ -81,7 +81,7 @@ AssetsManagerEx::AssetsManagerEx(const std::string& manifestUrl, const std::stri
_fileUtils = FileUtils::getInstance(); _fileUtils = FileUtils::getInstance();
_updateState = State::UNCHECKED; _updateState = State::UNCHECKED;
_downloader = std::make_shared<Downloader>(); _downloader = std::shared_ptr<Downloader>(new Downloader);
_downloader->setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); _downloader->setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
_downloader->_onError = std::bind(&AssetsManagerEx::onError, this, std::placeholders::_1); _downloader->_onError = std::bind(&AssetsManagerEx::onError, this, std::placeholders::_1);
_downloader->_onProgress = std::bind(&AssetsManagerEx::onProgress, _downloader->_onProgress = std::bind(&AssetsManagerEx::onProgress,

View File

@ -392,6 +392,7 @@ void Downloader::downloadToBufferSync(const std::string &srcUrl, unsigned char *
void Downloader::downloadToBuffer(const std::string &srcUrl, const std::string &customId, const StreamData &buffer, const ProgressData &data) void Downloader::downloadToBuffer(const std::string &srcUrl, const std::string &customId, const StreamData &buffer, const ProgressData &data)
{ {
std::weak_ptr<Downloader> ptr = shared_from_this(); std::weak_ptr<Downloader> ptr = shared_from_this();
std::shared_ptr<Downloader> shared = ptr.lock();
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if (!curl) if (!curl)
{ {
@ -463,6 +464,7 @@ void Downloader::downloadSync(const std::string &srcUrl, const std::string &stor
void Downloader::download(const std::string &srcUrl, const std::string &customId, const FileDescriptor &fDesc, const ProgressData &data) void Downloader::download(const std::string &srcUrl, const std::string &customId, const FileDescriptor &fDesc, const ProgressData &data)
{ {
std::weak_ptr<Downloader> ptr = shared_from_this(); std::weak_ptr<Downloader> ptr = shared_from_this();
std::shared_ptr<Downloader> shared = ptr.lock();
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if (!curl) if (!curl)
{ {
@ -524,6 +526,7 @@ void Downloader::batchDownloadSync(const DownloadUnits &units, const std::string
{ {
// Make sure downloader won't be released // Make sure downloader won't be released
std::weak_ptr<Downloader> ptr = shared_from_this(); std::weak_ptr<Downloader> ptr = shared_from_this();
std::shared_ptr<Downloader> shared = ptr.lock();
if (units.size() != 0) if (units.size() != 0)
{ {