Skip to content

Commit

Permalink
Add assertions to ensure texture width and height >= 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Robyt3 committed Jul 20, 2023
1 parent 2e39c23 commit 0cd9af5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/engine/client/graphics_threaded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ static bool ConvertToRGBA(uint8_t *pDest, const uint8_t *pSrc, size_t SrcWidth,

int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData)
{
dbg_assert(Width > 0, "LoadTextureRawSub: Width is negative or zero");
dbg_assert(Height > 0, "LoadTextureRawSub: Height is negative or zero");

CCommandBuffer::SCommand_Texture_Update Cmd;
Cmd.m_Slot = TextureID.Id();
Cmd.m_X = x;
Expand Down Expand Up @@ -421,6 +424,9 @@ bool CGraphics_Threaded::IsSpriteTextureFullyTransparent(CImageInfo &FromImageIn

IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags, const char *pTexName)
{
dbg_assert(Width > 0, "LoadTextureRaw: Width is negative or zero");
dbg_assert(Height > 0, "LoadTextureRaw: Height is negative or zero");

// don't waste memory on texture if we are stress testing
#ifdef CONF_DEBUG
if(g_Config.m_DbgStress && m_InvalidTexture.IsValid())
Expand Down Expand Up @@ -533,6 +539,9 @@ IGraphics::CTextureHandle CGraphics_Threaded::InvalidTexture() const

bool CGraphics_Threaded::LoadTextTextures(int Width, int Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, void *pTextData, void *pTextOutlineData)
{
dbg_assert(Width > 0, "LoadTextTextures: Width is negative or zero");
dbg_assert(Height > 0, "LoadTextTextures: Height is negative or zero");

if(Width == 0 || Height == 0)
return false;

Expand Down Expand Up @@ -608,6 +617,9 @@ bool CGraphics_Threaded::UnloadTextTextures(CTextureHandle &TextTexture, CTextur

bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureID, int x, int y, int Width, int Height, const void *pData)
{
dbg_assert(Width > 0, "UpdateTextTexture: Width is negative or zero");
dbg_assert(Height > 0, "UpdateTextTexture: Height is negative or zero");

CCommandBuffer::SCommand_TextTexture_Update Cmd;
Cmd.m_Slot = TextureID.Id();
Cmd.m_X = x;
Expand Down

0 comments on commit 0cd9af5

Please sign in to comment.