4008: removed the operator int() from IGraphics::CTextureHandle and ISound:… r=Jupeyy a=ChillerDragon

…:CSampleHandle in order to catch more bugs

(cherry picked from commit 563f1d0c52)



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Magnus Auvinen <magnus.auvinen@gmail.com>
This commit is contained in:
bors[bot] 2021-08-15 08:14:02 +00:00 committed by GitHub
commit bfe8fac232
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 35 additions and 34 deletions

View file

@ -264,19 +264,19 @@ void CGraphics_Threaded::LinesDraw(const CLineItem *pArray, int Num)
int CGraphics_Threaded::UnloadTexture(CTextureHandle Index)
{
if(Index == m_InvalidTexture)
if(Index.Id() == m_InvalidTexture.Id())
return 0;
if(Index < 0)
if(!Index.IsValid())
return 0;
CCommandBuffer::SCommand_Texture_Destroy Cmd;
Cmd.m_Slot = Index;
Cmd.m_Slot = Index.Id();
AddCmd(
Cmd, [] { return true; }, "failed to unload texture.");
m_TextureIndices[Index] = m_FirstFreeTexture;
m_FirstFreeTexture = Index;
m_TextureIndices[Index.Id()] = m_FirstFreeTexture;
m_FirstFreeTexture = Index.Id();
return 0;
}
@ -311,7 +311,7 @@ static int ImageFormatToPixelSize(int Format)
int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData)
{
CCommandBuffer::SCommand_Texture_Update Cmd;
Cmd.m_Slot = TextureID;
Cmd.m_Slot = TextureID.Id();
Cmd.m_X = x;
Cmd.m_Y = y;
Cmd.m_Width = Width;
@ -483,7 +483,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Heig
IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags)
{
int l = str_length(pFilename);
int ID;
IGraphics::CTextureHandle ID;
CImageInfo Img;
if(l < 3)
@ -495,9 +495,9 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename,
ID = LoadTextureRaw(Img.m_Width, Img.m_Height, Img.m_Format, Img.m_pData, StoreFormat, Flags, pFilename);
free(Img.m_pData);
if(ID != m_InvalidTexture && g_Config.m_Debug)
if(ID.Id() != m_InvalidTexture.Id() && g_Config.m_Debug)
dbg_msg("graphics/texture", "loaded %s", pFilename);
return CreateTextureHandle(ID);
return ID;
}
return m_InvalidTexture;
@ -688,7 +688,7 @@ void CGraphics_Threaded::ScreenshotDirect()
void CGraphics_Threaded::TextureSet(CTextureHandle TextureID)
{
dbg_assert(m_Drawing == 0, "called Graphics()->TextureSet within begin");
m_State.m_Texture = TextureID;
m_State.m_Texture = TextureID.Id();
}
void CGraphics_Threaded::Clear(float r, float g, float b)

View file

@ -1098,7 +1098,7 @@ public:
if(Graphics()->IsTextBufferingEnabled())
{
float OutlineColor[4] = {m_OutlineColor.r, m_OutlineColor.g, m_OutlineColor.b, m_OutlineColor.a * m_Color.a};
Graphics()->TextQuadsEnd(pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0], pFont->m_aTextures[1], OutlineColor);
Graphics()->TextQuadsEnd(pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0].Id(), pFont->m_aTextures[1].Id(), OutlineColor);
}
else
{
@ -1756,7 +1756,7 @@ public:
{
Graphics()->TextureClear();
// render buffered text
Graphics()->RenderText(TextContainer.m_StringInfo.m_QuadBufferContainerIndex, TextContainer.m_StringInfo.m_QuadNum, pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0], pFont->m_aTextures[1], (float *)pTextColor, (float *)pTextOutlineColor);
Graphics()->RenderText(TextContainer.m_StringInfo.m_QuadBufferContainerIndex, TextContainer.m_StringInfo.m_QuadNum, pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0].Id(), pFont->m_aTextures[1].Id(), (float *)pTextColor, (float *)pTextOutlineColor);
}
else
{

View file

@ -192,7 +192,8 @@ public:
{
}
operator int() const { return m_Id; }
bool IsValid() const { return Id() >= 0; }
int Id() const { return m_Id; }
};
int ScreenWidth() const { return m_ScreenWidth; }

View file

@ -136,7 +136,7 @@ const CCountryFlags::CCountryFlag *CCountryFlags::GetByIndex(int Index) const
void CCountryFlags::Render(int CountryCode, const ColorRGBA *pColor, float x, float y, float w, float h)
{
const CCountryFlag *pFlag = GetByCountryCode(CountryCode);
if(pFlag->m_Texture != -1)
if(pFlag->m_Texture.IsValid())
{
Graphics()->TextureSet(pFlag->m_Texture);
Graphics()->QuadsBegin();

View file

@ -758,7 +758,7 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
int CurWeapon = pCharacter->m_Weapon % NUM_WEAPONS;
int QuadOffset = (CurWeapon * 2) * 10 + QuadOffsetSixup;
if(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon] != -1)
if(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon].IsValid())
{
Graphics()->TextureSet(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon]);

View file

@ -109,7 +109,7 @@ void CItems::RenderProjectile(const CProjectileData *pCurrent, int ItemID)
Graphics()->QuadsSetRotation(0);
}
if(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon] != -1)
if(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon].IsValid())
{
Graphics()->TextureSet(GameClient()->m_GameSkin.m_SpriteWeaponProjectiles[CurWeapon]);
Graphics()->SetColor(1.f, 1.f, 1.f, Alpha);

View file

@ -135,9 +135,9 @@ void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
CreateKillmessageNamesIfNotCreated(Kill);
bool KillMsgValid = (Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_ColorableRenderSkin.m_Body != -1) || (!Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_OriginalRenderSkin.m_Body != -1);
bool KillMsgValid = (Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_ColorableRenderSkin.m_Body.IsValid()) || (!Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_OriginalRenderSkin.m_Body.IsValid());
// if killer != victim, killer must be valid too
KillMsgValid &= Kill.m_KillerID == Kill.m_VictimID || ((Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_ColorableRenderSkin.m_Body != -1) || (!Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_OriginalRenderSkin.m_Body != -1));
KillMsgValid &= Kill.m_KillerID == Kill.m_VictimID || ((Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_ColorableRenderSkin.m_Body.IsValid()) || (!Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_OriginalRenderSkin.m_Body.IsValid()));
if(KillMsgValid)
{
// add the message

View file

@ -251,7 +251,7 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit
else if(n == MAP_IMAGE_ENTITY_LAYER_TYPE_TUNE && !GameTypeHasTuneLayer)
BuildThisLayer = false;
dbg_assert(m_EntitiesTextures[(EntitiesModType * 2) + (int)EntitesAreMasked][n] == -1, "entities texture already loaded when it should not be");
dbg_assert(!m_EntitiesTextures[(EntitiesModType * 2) + (int)EntitesAreMasked][n].IsValid(), "entities texture already loaded when it should not be");
if(BuildThisLayer)
{
@ -324,7 +324,7 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit
}
else
{
if(m_TransparentTexture == -1)
if(!m_TransparentTexture.IsValid())
{
// set everything transparent
mem_zero(pBuildImgData, BuildImageSize);
@ -387,7 +387,7 @@ void CMapImages::ChangeEntitiesPath(const char *pPath)
{
for(int n = 0; n < MAP_IMAGE_ENTITY_LAYER_TYPE_COUNT; ++n)
{
if(m_EntitiesTextures[i][n] != -1)
if(m_EntitiesTextures[i][n].IsValid())
Graphics()->UnloadTexture(m_EntitiesTextures[i][n]);
m_EntitiesTextures[i][n] = IGraphics::CTextureHandle();
}
@ -404,7 +404,7 @@ void CMapImages::SetTextureScale(int Scale)
m_TextureScale = Scale;
if(Graphics() && m_OverlayCenterTexture != -1) // check if component was initialized
if(Graphics() && m_OverlayCenterTexture.IsValid()) // check if component was initialized
{
// reinitialize component
Graphics()->UnloadTexture(m_OverlayBottomTexture);
@ -476,17 +476,17 @@ void CMapImages::InitOverlayTextures()
TextureSize = clamp(TextureSize, 2, 64);
int TextureToVerticalCenterOffset = (64 - TextureSize) / 2; // should be used to move texture to the center of 64 pixels area
if(m_OverlayBottomTexture == -1)
if(!m_OverlayBottomTexture.IsValid())
{
m_OverlayBottomTexture = UploadEntityLayerText(TextureSize / 2, 64, 32 + TextureToVerticalCenterOffset / 2);
}
if(m_OverlayTopTexture == -1)
if(!m_OverlayTopTexture.IsValid())
{
m_OverlayTopTexture = UploadEntityLayerText(TextureSize / 2, 64, TextureToVerticalCenterOffset / 2);
}
if(m_OverlayCenterTexture == -1)
if(!m_OverlayCenterTexture.IsValid())
{
m_OverlayCenterTexture = UploadEntityLayerText(TextureSize, 64, TextureToVerticalCenterOffset);
}

View file

@ -2472,7 +2472,7 @@ void CMenus::RenderThemeSelection(CUIRect MainView, bool Header)
Item.m_Rect.VSplitLeft(Item.m_Rect.h * 2.0f, &Icon, &Item.m_Rect);
// draw icon if it exists
if(Theme.m_IconTexture != -1)
if(Theme.m_IconTexture.IsValid())
{
Icon.VMargin(6.0f, &Icon);
Icon.HMargin(3.0f, &Icon);

View file

@ -426,7 +426,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
Item.m_Rect.x += (OldWidth - Item.m_Rect.w) / 2.0f;
ColorRGBA Color(1.0f, 1.0f, 1.0f, 1.0f);
m_pClient->m_CountryFlags.Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
if(pEntry->m_Texture != -1)
if(pEntry->m_Texture.IsValid())
UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0);
}
}

View file

@ -24,7 +24,7 @@ void CMenus::LoadEntities(SCustomEntities *pEntitiesItem, void *pUser)
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(pEntitiesItem->m_RenderTexture == -1)
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
}
@ -40,7 +40,7 @@ void CMenus::LoadEntities(SCustomEntities *pEntitiesItem, void *pUser)
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(pEntitiesItem->m_RenderTexture == -1)
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
else
@ -52,7 +52,7 @@ void CMenus::LoadEntities(SCustomEntities *pEntitiesItem, void *pUser)
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(pEntitiesItem->m_RenderTexture == -1)
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
}
@ -228,7 +228,7 @@ void ClearAssetList(sorted_array<TName> &List, IGraphics *pGraphics)
{
for(int i = 0; i < List.size(); ++i)
{
if(List[i].m_RenderTexture != -1)
if(List[i].m_RenderTexture.IsValid())
pGraphics->UnloadTexture(List[i].m_RenderTexture);
List[i].m_RenderTexture = IGraphics::CTextureHandle();
}
@ -243,7 +243,7 @@ void CMenus::ClearCustomItems(int CurTab)
{
for(auto &Image : m_EntitiesList[i].m_aImages)
{
if(Image.m_Texture != -1)
if(Image.m_Texture.IsValid())
Graphics()->UnloadTexture(Image.m_Texture);
Image.m_Texture = IGraphics::CTextureHandle();
}
@ -462,7 +462,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
ItemRect.HSplitTop(15, &ItemRect, &TextureRect);
TextureRect.HSplitTop(10, NULL, &TextureRect);
UI()->DoLabelScaled(&ItemRect, s->m_aName, ItemRect.h - 2, 0);
if(s->m_RenderTexture != -1)
if(s->m_RenderTexture.IsValid())
{
Graphics()->WrapClamp();
Graphics()->TextureSet(s->m_RenderTexture);

View file

@ -594,7 +594,7 @@ public:
bool IsSixup()
{
return m_SpriteNinjaBarFullLeft != -1;
return m_SpriteNinjaBarFullLeft.IsValid();
}
};