+ TextureManager::TextureId maskTextureId = INVALID_TEXTURE_ID;
+ TextureInfo& textureInfo(mTextureCacheManager[textureCacheIndex]);
+ if(textureInfo.maskTextureId != INVALID_TEXTURE_ID)
+ {
+ maskTextureId = textureInfo.maskTextureId;
+ }
+
+ // the case that LoadingQueue is working.
+ if(mLoadingQueueTextureId != INVALID_TEXTURE_ID)
+ {
+ // If textureId is not same, this observer need to delete when ProcessRemoveQueue() is called.
+ TextureUploadObserver* queueObserver = nullptr;
+ if(mLoadingQueueTextureId != textureId)
+ {
+ queueObserver = observer;
+ }
+
+ // Remove textureId after NotifyObserver finished
+ if(maskTextureId != INVALID_TEXTURE_ID)
+ {
+ if(textureInfo.loadState != LoadState::CANCELLED)
+ {
+ mRemoveQueue.PushBack(QueueElement(maskTextureId, nullptr));
+ }
+ }
+ mRemoveQueue.PushBack(QueueElement(textureId, queueObserver));
+ }
+ else
+ {
+ // Remove its observer
+ RemoveTextureObserver(textureInfo, observer);
+
+ // Keep loadState due to the textureInfo validate problem.
+ auto textureLoadState = textureInfo.loadState;
+
+ // Remove textureId in CacheManager
+ mTextureCacheManager.RemoveCache(textureInfo);
+
+ // Remove maskTextureId in CacheManager
+ if(maskTextureId != INVALID_TEXTURE_ID)
+ {
+ TextureCacheIndex maskCacheIndex = mTextureCacheManager.GetCacheIndexFromId(maskTextureId);
+ if(maskCacheIndex != INVALID_CACHE_INDEX)
+ {
+ TextureInfo& maskTextureInfo(mTextureCacheManager[maskCacheIndex]);
+
+ // Only Remove maskTexture when texture's loadState is not CANCELLED. because it is already deleted.
+ if(textureLoadState != LoadState::CANCELLED)
+ {
+ mTextureCacheManager.RemoveCache(maskTextureInfo);
+ }
+ }
+ }
+ }