Don't delete a texture when async load is pending

This commit is contained in:
Flyinghead 2018-12-30 19:19:27 +01:00
parent e7fee139e4
commit 3f98c2ba3c
3 changed files with 15 additions and 6 deletions

View File

@ -54,6 +54,7 @@ void CustomTexture::LoaderThread()
texture->custom_height = height;
texture->custom_image_data = image_data;
}
texture->custom_load_in_progress = false;
}
wakeup_thread.Wait();

View File

@ -270,6 +270,7 @@ struct TextureCacheData
u8* custom_image_data; // loaded custom image data
u32 custom_width;
u32 custom_height;
bool custom_load_in_progress;
void PrintTextureName();
@ -285,5 +286,5 @@ struct TextureCacheData
void CheckCustomTexture();
//true if : dirty or paletted texture and hashes don't match
bool NeedsUpdate();
void Delete();
bool Delete();
};

View File

@ -408,6 +408,7 @@ void TextureCacheData::Update()
}
if (settings.rend.CustomTextures)
{
custom_load_in_progress = true;
custom_texture.LoadCustomTextureAsync(this);
}
@ -560,8 +561,11 @@ bool TextureCacheData::NeedsUpdate() {
return rc;
}
void TextureCacheData::Delete()
bool TextureCacheData::Delete()
{
if (custom_load_in_progress)
return false;
if (pData) {
#if FEAT_HAS_SOFTREND
_mm_free(pData);
@ -579,6 +583,8 @@ void TextureCacheData::Delete()
lock_block=0;
if (custom_image_data != NULL)
delete [] custom_image_data;
return true;
}
@ -951,10 +957,11 @@ void CollectCleanup() {
}
for (size_t i=0; i<list.size(); i++) {
//printf("Deleting %d\n",TexCache[list[i]].texID);
TexCache[list[i]].Delete();
TexCache.erase(list[i]);
if (TexCache[list[i]].Delete())
{
//printf("Deleting %d\n", TexCache[list[i]].texID);
TexCache.erase(list[i]);
}
}
}