diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 5c22d9d80..c4190da02 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -657,12 +657,6 @@ bool CGraphics_Threaded::LoadPNG(CImageInfo *pImg, const char *pFilename, int St return true; } -void CGraphics_Threaded::FreePNG(CImageInfo *pImg) -{ - free(pImg->m_pData); - pImg->m_pData = NULL; -} - bool CGraphics_Threaded::CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) { dbg_assert(DivX != 0 && DivY != 0, "Passing 0 to this function is not allowed."); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 9c8f1f702..623d9bed8 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -983,7 +983,6 @@ public: // simple uncompressed RGBA loaders IGraphics::CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) override; bool LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) override; - void FreePNG(CImageInfo *pImg) override; bool CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) override; bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) override; diff --git a/src/engine/client/serverbrowser_http.cpp b/src/engine/client/serverbrowser_http.cpp index 8c66b3332..dae761de8 100644 --- a/src/engine/client/serverbrowser_http.cpp +++ b/src/engine/client/serverbrowser_http.cpp @@ -225,7 +225,7 @@ void CChooseMaster::CJob::Run() pHead->Wait(); if(pHead->State() == EHttpState::ABORTED || State() == IJob::STATE_ABORTED) { - log_debug("serverbrowse_http", "master chooser aborted"); + log_debug("serverbrowser_http", "master chooser aborted"); return; } if(pHead->State() != EHttpState::DONE) @@ -248,7 +248,7 @@ void CChooseMaster::CJob::Run() auto Time = std::chrono::duration_cast(time_get_nanoseconds() - StartTime); if(pGet->State() == EHttpState::ABORTED || State() == IJob::STATE_ABORTED) { - log_debug("serverbrowse_http", "master chooser aborted"); + log_debug("serverbrowser_http", "master chooser aborted"); return; } if(pGet->State() != EHttpState::DONE) @@ -268,7 +268,7 @@ void CChooseMaster::CJob::Run() continue; } int AgeS = SanitizeAge(pGet->ResultAgeSeconds()); - log_info("serverbrowse_http", "found master, url='%s' time=%dms age=%ds", pUrl, (int)Time.count(), AgeS); + log_info("serverbrowser_http", "found master, url='%s' time=%dms age=%ds", pUrl, (int)Time.count(), AgeS); aTimeMs[i] = Time.count(); aAgeS[i] = AgeS; @@ -293,11 +293,11 @@ void CChooseMaster::CJob::Run() } if(BestIndex == -1) { - log_error("serverbrowse_http", "WARNING: no usable masters found"); + log_error("serverbrowser_http", "WARNING: no usable masters found"); return; } - log_info("serverbrowse_http", "determined best master, url='%s' time=%dms age=%ds", m_pData->m_aaUrls[BestIndex], BestTime, BestAge); + log_info("serverbrowser_http", "determined best master, url='%s' time=%dms age=%ds", m_pData->m_aaUrls[BestIndex], BestTime, BestAge); m_pData->m_BestIndex.store(BestIndex); } @@ -374,7 +374,7 @@ void CServerBrowserHttp::Update() { if(!m_pChooseMaster->IsRefreshing()) { - log_error("serverbrowse_http", "no working serverlist URL found"); + log_error("serverbrowser_http", "no working serverlist URL found"); m_State = STATE_NO_MASTER; } return; @@ -402,7 +402,7 @@ void CServerBrowserHttp::Update() json_value_free(pJson); if(!Success) { - log_error("serverbrowse_http", "failed getting serverlist, trying to find best URL"); + log_error("serverbrowser_http", "failed getting serverlist, trying to find best URL"); m_pChooseMaster->Reset(); m_pChooseMaster->Refresh(); } @@ -413,7 +413,7 @@ void CServerBrowserHttp::Update() int Age = SanitizeAge(pGetServers->ResultAgeSeconds()); if(Age > 300) { - log_info("serverbrowse_http", "got stale serverlist, age=%ds, trying to find best URL", Age); + log_info("serverbrowser_http", "got stale serverlist, age=%ds, trying to find best URL", Age); m_pChooseMaster->Refresh(); } } @@ -494,7 +494,7 @@ bool CServerBrowserHttp::Parse(json_value *pJson, std::vector *pvSe NETADDR ParsedAddr; if(ServerbrowserParseUrl(&ParsedAddr, Addresses[a])) { - log_debug("dbg/serverbrowser", "unknown address, i=%d a=%d", i, a); + // log_debug("serverbrowser_http", "unknown address, i=%d a=%d", i, a); // Skip unknown addresses. continue; } diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 7bd43092d..0c54fac62 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -97,6 +97,15 @@ public: */ uint8_t *m_pData = nullptr; + void Free() + { + m_Width = 0; + m_Height = 0; + m_Format = FORMAT_ERROR; + free(m_pData); + m_pData = nullptr; + } + static size_t PixelSize(EImageFormat Format) { dbg_assert(Format != FORMAT_ERROR, "Format invalid"); @@ -322,7 +331,6 @@ public: virtual const TTwGraphicsGpuList &GetGpus() const = 0; virtual bool LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) = 0; - virtual void FreePNG(CImageInfo *pImg) = 0; virtual bool CheckImageDivisibility(const char *pFileName, CImageInfo &Img, int DivX, int DivY, bool AllowResize) = 0; virtual bool IsImageFormatRGBA(const char *pFileName, CImageInfo &Img) = 0; diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index 3f8938e39..80b3ae177 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -286,8 +286,7 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit } free(pBuildImgData); - - Graphics()->FreePNG(&ImgInfo); + ImgInfo.Free(); } } diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index db19206ad..fefe2d229 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2249,7 +2249,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser } if(Info.m_Format != CImageInfo::FORMAT_RGBA) { - pSelf->Graphics()->FreePNG(&Info); + Info.Free(); char aError[IO_MAX_PATH_LENGTH + 64]; str_format(aError, sizeof(aError), "Failed to load menu image from '%s': must be an RGBA image", aPath); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus", aError); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index e2014d389..1eab9762a 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1944,8 +1944,7 @@ CMenus::CCommunityIconLoadJob::CCommunityIconLoadJob(CMenus *pMenus, const char CMenus::CCommunityIconLoadJob::~CCommunityIconLoadJob() { - free(m_ImageInfo.m_pData); - m_ImageInfo.m_pData = nullptr; + m_ImageInfo.Free(); } int CMenus::CommunityIconScan(const char *pName, int IsDir, int DirType, void *pUser) @@ -1983,14 +1982,14 @@ bool CMenus::LoadCommunityIconFile(const char *pPath, int DirType, CImageInfo &I } if(Info.m_Format != CImageInfo::FORMAT_RGBA) { - Graphics()->FreePNG(&Info); + Info.Free(); str_format(aError, sizeof(aError), "Failed to load community icon from '%s': must be an RGBA image", pPath); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError); return false; } if(!Storage()->CalculateHashes(pPath, DirType, &Sha256)) { - Graphics()->FreePNG(&Info); + Info.Free(); str_format(aError, sizeof(aError), "Failed to load community icon from '%s': could not calculate hash", pPath); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menus/browser", aError); return false; diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index ad6728cde..af4210005 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -293,7 +293,7 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info) for(int i = 0; i < 6; ++i) Skin.m_ColorableSkin.m_aEyes[i] = Graphics()->LoadSpriteTexture(Info, &g_pData->m_aSprites[SPRITE_TEE_EYE_NORMAL + i]); - Graphics()->FreePNG(&Info); + Info.Free(); if(g_Config.m_Debug) { diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 1dd1e3cd3..3cae8b052 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -3104,8 +3104,7 @@ void CGameClient::LoadGameSkin(const char *pPath, bool AsDir) } m_GameSkinLoaded = true; - - Graphics()->FreePNG(&ImgInfo); + ImgInfo.Free(); } } @@ -3149,7 +3148,7 @@ void CGameClient::LoadEmoticonsSkin(const char *pPath, bool AsDir) m_EmoticonsSkin.m_aSpriteEmoticons[i] = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_OOP + i]); m_EmoticonsSkinLoaded = true; - Graphics()->FreePNG(&ImgInfo); + ImgInfo.Free(); } } @@ -3220,7 +3219,7 @@ void CGameClient::LoadParticlesSkin(const char *pPath, bool AsDir) m_ParticlesSkin.m_aSpriteParticles[9] = m_ParticlesSkin.m_SpriteParticleHit; m_ParticlesSkinLoaded = true; - free(ImgInfo.m_pData); + ImgInfo.Free(); } } @@ -3319,7 +3318,7 @@ void CGameClient::LoadHudSkin(const char *pPath, bool AsDir) m_HudSkin.m_SpriteHudDummyCopy = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_HUD_DUMMY_COPY]); m_HudSkinLoaded = true; - free(ImgInfo.m_pData); + ImgInfo.Free(); } } @@ -3364,7 +3363,7 @@ void CGameClient::LoadExtrasSkin(const char *pPath, bool AsDir) m_ExtrasSkin.m_SpriteParticleSnowflake = Graphics()->LoadSpriteTexture(ImgInfo, &g_pData->m_aSprites[SPRITE_PART_SNOWFLAKE]); m_ExtrasSkin.m_aSpriteParticles[0] = m_ExtrasSkin.m_SpriteParticleSnowflake; m_ExtrasSkinLoaded = true; - free(ImgInfo.m_pData); + ImgInfo.Free(); } } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index ff0cb353d..19f8a5003 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4369,8 +4369,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup std::shared_ptr pImg = m_Map.m_vpImages[m_SelectedImage]; Graphics()->UnloadTexture(&(pImg->m_Texture)); - free(pImg->m_pData); - pImg->m_pData = nullptr; + pImg->Free(); *pImg = ImgInfo; str_copy(pImg->m_aName, aBuf); pImg->m_External = IsVanillaImage(pImg->m_aName); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index ef0f4e9f0..546b3785c 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -2107,8 +2107,7 @@ CUi::EPopupMenuFunctionResult CEditor::PopupEvent(void *pContext, CUIRect View, if(pEditor->m_PopupEventType == POPEVENT_PIXELART_BIG_IMAGE || pEditor->m_PopupEventType == POPEVENT_PIXELART_MANY_COLORS) { - free(pEditor->m_TileartImageInfo.m_pData); - pEditor->m_TileartImageInfo.m_pData = nullptr; + pEditor->m_TileartImageInfo.Free(); } return CUi::POPUP_CLOSE_CURRENT; diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index c58fc5e6a..816e3d93c 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -212,8 +212,7 @@ void CEditor::AddTileart(bool IgnoreHistory) m_EditorHistory.RecordAction(std::make_shared(this, ImageCount, m_aTileartFilename, IndexMap)); } - free(m_TileartImageInfo.m_pData); - m_TileartImageInfo.m_pData = nullptr; + m_TileartImageInfo.Free(); m_Map.OnModify(); m_Dialog = DIALOG_NONE; } @@ -226,8 +225,7 @@ void CEditor::TileartCheckColors() { m_PopupEventType = CEditor::POPEVENT_PIXELART_TOO_MANY_COLORS; m_PopupEventActivated = true; - free(m_TileartImageInfo.m_pData); - m_TileartImageInfo.m_pData = nullptr; + m_TileartImageInfo.Free(); } else if(NumColorGroups > 1) { diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 3ba13bd3d..4e2b95ce1 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1217,7 +1217,7 @@ void CGameContext::ConSetEyeEmote(IConsole::IResult *pResult, "chatresp", (pPlayer->m_EyeEmoteEnabled) ? "You can now use the preset eye emotes." : - "You don't have any eye emotes, remember to bind some. (until you die)"); + "You don't have any eye emotes, remember to bind some."); return; } else if(str_comp_nocase(pResult->GetString(0), "on") == 0) @@ -1231,7 +1231,7 @@ void CGameContext::ConSetEyeEmote(IConsole::IResult *pResult, "chatresp", (pPlayer->m_EyeEmoteEnabled) ? "You can now use the preset eye emotes." : - "You don't have any eye emotes, remember to bind some. (until you die)"); + "You don't have any eye emotes, remember to bind some."); } void CGameContext::ConEyeEmote(IConsole::IResult *pResult, void *pUserData)