Fix check for invalid texture after LoadTextureRaw

The handle returned by `LoadTextureRaw` is either valid or invalid (i.e. `-1`) but never the invalid texture itself.

Additionally, ensure that the `LoadTexture` function returns the invalid texture also when `LoadTextureRaw` fails.
This commit is contained in:
Robert Müller 2023-11-03 23:54:03 +01:00
parent 07e336e0f4
commit fdaa343219

View file

@ -482,11 +482,14 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename,
CImageInfo Img;
if(LoadPNG(&Img, pFilename, StorageType))
{
IGraphics::CTextureHandle ID = LoadTextureRaw(Img.m_Width, Img.m_Height, Img.m_Format, Img.m_pData, Flags, pFilename);
free(Img.m_pData);
if(ID.Id() != m_InvalidTexture.Id() && g_Config.m_Debug)
dbg_msg("graphics/texture", "loaded %s", pFilename);
return ID;
CTextureHandle ID = LoadTextureRaw(Img.m_Width, Img.m_Height, Img.m_Format, Img.m_pData, Flags, pFilename);
FreePNG(&Img);
if(ID.IsValid())
{
if(g_Config.m_Debug)
dbg_msg("graphics/texture", "loaded %s", pFilename);
return ID;
}
}
return m_InvalidTexture;