Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffdf3d7

Browse files
committed
assure threading safety
1 parent fb6ea21 commit ffdf3d7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cocos/renderer/CCTextureCache.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,27 @@ void TextureCache::addImageAsync(const std::string &path, const std::function<vo
143143

144144
void TextureCache::unbindImageAsync(const std::string& filename)
145145
{
146+
_imageInfoMutex.lock();
146147
if (_imageInfoQueue && !_imageInfoQueue->empty())
147148
{
148-
_imageInfoMutex.lock();
149149
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename);
150150
auto found = std::find_if(_imageInfoQueue->begin(), _imageInfoQueue->end(), [&fullpath](ImageInfo* ptr)->bool{ return ptr->asyncStruct->filename == fullpath; });
151151
if (found != _imageInfoQueue->end())
152152
{
153153
(*found)->asyncStruct->callback = nullptr;
154154
}
155-
_imageInfoMutex.unlock();
156155
}
156+
_imageInfoMutex.unlock();
157157
}
158158

159159
void TextureCache::unbindAllImageAsync()
160160
{
161+
_imageInfoMutex.lock();
161162
if (_imageInfoQueue && !_imageInfoQueue->empty())
162163
{
163-
_imageInfoMutex.lock();
164164
std::for_each(_imageInfoQueue->begin(), _imageInfoQueue->end(), [](ImageInfo* ptr) { ptr->asyncStruct->callback = nullptr; });
165-
_imageInfoMutex.unlock();
166165
}
166+
_imageInfoMutex.unlock();
167167
}
168168

169169

0 commit comments

Comments
 (0)