diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index efe7ff03d72..13c3838a93f 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -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; @@ -353,6 +356,8 @@ int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureID, int x, int y IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTextureImpl(CImageInfo &FromImageInfo, int x, int y, int w, int h) { + dbg_assert(w > 0, "LoadSpriteTextureImpl: Width is negative or zero"); + dbg_assert(h > 0, "LoadSpriteTextureImpl: Height is negative or zero"); int bpp = ImageFormatToPixelSize(FromImageInfo.m_Format); m_vSpriteHelper.resize((size_t)w * h * bpp); @@ -421,6 +426,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()) @@ -533,6 +541,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; @@ -608,6 +619,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; @@ -779,6 +793,11 @@ bool CGraphics_Threaded::IsImageFormatRGBA(const char *pFileName, CImageInfo &Im void CGraphics_Threaded::CopyTextureBufferSub(uint8_t *pDestBuffer, uint8_t *pSourceBuffer, int FullWidth, int FullHeight, int ColorChannelCount, int SubOffsetX, int SubOffsetY, int SubCopyWidth, int SubCopyHeight) { + dbg_assert(FullWidth > 0, "CopyTextureBufferSub: FullWidth is negative or zero"); + dbg_assert(FullHeight > 0, "CopyTextureBufferSub: FullHeight is negative or zero"); + dbg_assert(SubCopyWidth > 0, "CopyTextureBufferSub: SubCopyWidth is negative or zero"); + dbg_assert(SubCopyHeight > 0, "CopyTextureBufferSub: SubCopyHeight is negative or zero"); + for(int Y = 0; Y < SubCopyHeight; ++Y) { int ImgOffset = ((SubOffsetY + Y) * FullWidth * ColorChannelCount) + (SubOffsetX * ColorChannelCount); @@ -789,6 +808,15 @@ void CGraphics_Threaded::CopyTextureBufferSub(uint8_t *pDestBuffer, uint8_t *pSo void CGraphics_Threaded::CopyTextureFromTextureBufferSub(uint8_t *pDestBuffer, int DestWidth, int DestHeight, uint8_t *pSourceBuffer, int SrcWidth, int SrcHeight, int ColorChannelCount, int SrcSubOffsetX, int SrcSubOffsetY, int SrcSubCopyWidth, int SrcSubCopyHeight) { + dbg_assert(DestWidth > 0, "CopyTextureFromTextureBufferSub: DestWidth is negative or zero"); + dbg_assert(DestHeight > 0, "CopyTextureFromTextureBufferSub: DestHeight is negative or zero"); + dbg_assert(SrcWidth > 0, "CopyTextureFromTextureBufferSub: SrcWidth is negative or zero"); + dbg_assert(SrcHeight > 0, "CopyTextureFromTextureBufferSub: SrcHeight is negative or zero"); + dbg_assert(SrcSubOffsetX >= 0, "CopyTextureFromTextureBufferSub: SrcSubOffsetX is negative"); + dbg_assert(SrcSubOffsetY >= 0, "CopyTextureFromTextureBufferSub: SrcSubOffsetY is negative"); + dbg_assert(SrcSubCopyWidth > 0, "CopyTextureFromTextureBufferSub: SrcSubCopyWidth is negative or zero"); + dbg_assert(SrcSubCopyHeight > 0, "CopyTextureFromTextureBufferSub: SrcSubCopyHeight is negative or zero"); + for(int Y = 0; Y < SrcSubCopyHeight; ++Y) { int SrcImgOffset = ((SrcSubOffsetY + Y) * SrcWidth * ColorChannelCount) + (SrcSubOffsetX * ColorChannelCount);