diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index a528c101db..5758b6cecd 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -143,27 +143,27 @@ void TextureCache::addImageAsync(const std::string &path, const std::functionempty()) { + _imageInfoMutex.lock(); std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename); auto found = std::find_if(_imageInfoQueue->begin(), _imageInfoQueue->end(), [&fullpath](ImageInfo* ptr)->bool{ return ptr->asyncStruct->filename == fullpath; }); if (found != _imageInfoQueue->end()) { (*found)->asyncStruct->callback = nullptr; } + _imageInfoMutex.unlock(); } - _imageInfoMutex.unlock(); } void TextureCache::unbindAllImageAsync() { - _imageInfoMutex.lock(); if (_imageInfoQueue && !_imageInfoQueue->empty()) { + _imageInfoMutex.lock(); std::for_each(_imageInfoQueue->begin(), _imageInfoQueue->end(), [](ImageInfo* ptr) { ptr->asyncStruct->callback = nullptr; }); + _imageInfoMutex.unlock(); } - _imageInfoMutex.unlock(); }