Skip to content

Commit adcf647

Browse files
authored
Delete the pending AsyncStructs when TextureCache's loading thread destroyed (#2911)
1 parent e2c0d3c commit adcf647

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

core/renderer/TextureCache.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,18 @@ Texture2D* TextureCache::getDummyTexture()
416416
constexpr std::string_view key = "/dummy-texture"sv;
417417
// Gets the texture by key firstly.
418418
auto texture = this->getTextureForKey(key);
419-
if (texture) return texture;
419+
if (texture)
420+
return texture;
420421

421422
// If texture wasn't in cache, create it from RAW data.
422423
#ifdef NDEBUG
423424
unsigned char texls[] = {0, 0, 0, 0}; // 1*1 transparent picture
424425
#else
425426
unsigned char texls[] = {255, 0, 0, 255}; // 1*1 red picture
426427
#endif
427-
Image* image = new Image(); // Notes: andorid: VolatileTextureMgr traits image as dynmaic object
428+
Image* image = new Image(); // Notes: andorid: VolatileTextureMgr traits image as dynmaic object
428429
bool AX_UNUSED isOK = image->initWithRawData(texls, sizeof(texls), 1, 1, sizeof(unsigned char));
429-
texture = this->addImage(image, key);
430+
texture = this->addImage(image, key);
430431
image->release();
431432
return texture;
432433
}
@@ -560,12 +561,13 @@ Texture2D* TextureCache::addImage(const Data& imageData, std::string_view key)
560561
{
561562
AXASSERT(!imageData.isNull() && !key.empty(), "TextureCache: imageData MUST not be empty and key not empty");
562563

563-
Texture2D * texture = nullptr;
564+
Texture2D* texture = nullptr;
564565

565566
do
566567
{
567568
auto it = _textures.find(key);
568-
if (it != _textures.end()) {
569+
if (it != _textures.end())
570+
{
569571
texture = it->second;
570572
break;
571573
}
@@ -604,7 +606,6 @@ Texture2D* TextureCache::addImage(const Data& imageData, std::string_view key)
604606

605607
} while (0);
606608

607-
608609
return texture;
609610
}
610611

@@ -750,6 +751,12 @@ void TextureCache::waitForQuit()
750751
ul.unlock();
751752
if (_loadingThread)
752753
_loadingThread->join();
754+
755+
for (AsyncStruct* s : _asyncStructQueue)
756+
delete s;
757+
758+
_asyncStructQueue.clear();
759+
_requestQueue.clear();
753760
}
754761

755762
std::string TextureCache::getCachedTextureInfo() const
@@ -770,14 +777,14 @@ std::string TextureCache::getCachedTextureInfo() const
770777
totalBytes += bytes;
771778
count++;
772779
auto msg = fmt::format_to_z(tmp, "\"{}\" rc={} id={} {} x {} @ {} bpp => {} KB\n", texture.first,
773-
tex->getReferenceCount(), fmt::ptr(tex->getBackendTexture()), tex->getPixelsWide(),
774-
tex->getPixelsHigh(), bpp, bytes / 1024);
780+
tex->getReferenceCount(), fmt::ptr(tex->getBackendTexture()), tex->getPixelsWide(),
781+
tex->getPixelsHigh(), bpp, bytes / 1024);
775782

776783
ret += msg;
777784
}
778785

779-
auto msg = fmt::format_to_z(tmp, "TextureCache dumpDebugInfo: {} textures, for {} KB ({:.2f} MB)\n",
780-
count, totalBytes / 1024, totalBytes / (1024.0f * 1024.0f));
786+
auto msg = fmt::format_to_z(tmp, "TextureCache dumpDebugInfo: {} textures, for {} KB ({:.2f} MB)\n", count,
787+
totalBytes / 1024, totalBytes / (1024.0f * 1024.0f));
781788
ret += msg;
782789

783790
return ret;
@@ -850,7 +857,8 @@ void VolatileTextureMgr::addImage(Texture2D* tt, Image* image)
850857

851858
VolatileTexture* vt = getOrAddVolatileTexture(tt);
852859

853-
if(vt->_uiImage != image) {
860+
if (vt->_uiImage != image)
861+
{
854862
AX_SAFE_RELEASE(vt->_uiImage);
855863
image->retain();
856864
vt->_uiImage = image;
@@ -989,4 +997,4 @@ void VolatileTextureMgr::reloadTexture(Texture2D* texture, std::string_view file
989997

990998
#endif // AX_ENABLE_CACHE_TEXTURE_DATA
991999

992-
}
1000+
} // namespace ax

0 commit comments

Comments
 (0)