Merge pull request #7251 from Robyt3/Graphics-Texture-Index-DoubleFree-Assertion

Add assertion when double-freeing texture index, ensure OpenGL texture vectors are large enough
This commit is contained in:
Jupeyy 2023-09-25 18:51:04 +00:00 committed by GitHub
commit 958676ae84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 13 deletions

View file

@ -729,7 +729,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_MaxTexSize);
}
if(Slot >= (int)m_vTextures.size())
while(Slot >= (int)m_vTextures.size())
m_vTextures.resize(m_vTextures.size() * 2);
m_vTextures[Slot].m_ResizeWidth = -1.f;

View file

@ -579,7 +579,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Destroy(const CCommandBuff
void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, void *pTexData)
{
if(Slot >= (int)m_vTextures.size())
while(Slot >= (int)m_vTextures.size())
m_vTextures.resize(m_vTextures.size() * 2);
// resample if needed

View file

@ -264,18 +264,14 @@ void CGraphics_Threaded::LinesDraw(const CLineItem *pArray, int Num)
IGraphics::CTextureHandle CGraphics_Threaded::FindFreeTextureIndex()
{
int Tex = m_FirstFreeTexture;
if(Tex == -1)
const size_t CurSize = m_vTextureIndices.size();
if(m_FirstFreeTexture == CurSize)
{
const size_t CurSize = m_vTextureIndices.size();
m_vTextureIndices.resize(CurSize * 2);
for(size_t i = 0; i < CurSize - 1; ++i)
{
for(size_t i = 0; i < CurSize; ++i)
m_vTextureIndices[CurSize + i] = CurSize + i + 1;
}
m_vTextureIndices.back() = -1;
Tex = CurSize;
}
const size_t Tex = m_FirstFreeTexture;
m_FirstFreeTexture = m_vTextureIndices[Tex];
m_vTextureIndices[Tex] = -1;
return CreateTextureHandle(Tex);
@ -284,6 +280,8 @@ IGraphics::CTextureHandle CGraphics_Threaded::FindFreeTextureIndex()
void CGraphics_Threaded::FreeTextureIndex(CTextureHandle *pIndex)
{
dbg_assert(pIndex->IsValid(), "Cannot free invalid texture index");
dbg_assert(m_vTextureIndices[pIndex->Id()] == -1, "Cannot free already freed texture index");
m_vTextureIndices[pIndex->Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = pIndex->Id();
pIndex->Invalidate();
@ -2598,9 +2596,8 @@ int CGraphics_Threaded::Init()
// init textures
m_FirstFreeTexture = 0;
m_vTextureIndices.resize(CCommandBuffer::MAX_TEXTURES);
for(size_t i = 0; i < m_vTextureIndices.size() - 1; ++i)
for(size_t i = 0; i < m_vTextureIndices.size(); ++i)
m_vTextureIndices[i] = i + 1;
m_vTextureIndices.back() = -1;
m_FirstFreeVertexArrayInfo = -1;
m_FirstFreeBufferObjectIndex = -1;

View file

@ -819,7 +819,7 @@ class CGraphics_Threaded : public IEngineGraphics
CTextureHandle m_InvalidTexture;
std::vector<int> m_vTextureIndices;
int m_FirstFreeTexture;
size_t m_FirstFreeTexture;
int m_TextureMemoryUsage;
std::vector<uint8_t> m_vSpriteHelper;