mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add shared ptr to track usage
This commit is contained in:
parent
bc006dbf08
commit
370d37b8fd
|
@ -179,6 +179,8 @@ struct STextContainer
|
|||
// prefix of the containers text stored for debugging purposes
|
||||
char m_aDebugText[32];
|
||||
|
||||
STextContainerIndex m_ContainerIndex;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_pFont = nullptr;
|
||||
|
@ -206,6 +208,8 @@ struct STextContainer
|
|||
m_BoundingBox = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
m_aDebugText[0] = '\0';
|
||||
|
||||
m_ContainerIndex = STextContainerIndex{};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -257,7 +261,7 @@ class CTextRender : public IEngineTextRender
|
|||
FreeTextContainerIndex(Index);
|
||||
}
|
||||
|
||||
STextContainer &GetTextContainer(STextContainerIndex Index)
|
||||
STextContainer &GetTextContainer(const STextContainerIndex &Index)
|
||||
{
|
||||
dbg_assert(Index.Valid(), "Text container index was invalid.");
|
||||
if(Index.m_Index >= (int)m_vpTextContainers.size())
|
||||
|
@ -267,6 +271,10 @@ class CTextRender : public IEngineTextRender
|
|||
m_vpTextContainers.push_back(new STextContainer());
|
||||
}
|
||||
|
||||
if(m_vpTextContainers[Index.m_Index]->m_ContainerIndex.m_UseCount.get() != Index.m_UseCount.get())
|
||||
{
|
||||
m_vpTextContainers[Index.m_Index]->m_ContainerIndex = Index;
|
||||
}
|
||||
return *m_vpTextContainers[Index.m_Index];
|
||||
}
|
||||
|
||||
|
@ -1962,6 +1970,18 @@ public:
|
|||
return UTF8Off != -1;
|
||||
}
|
||||
|
||||
void OnPreWindowResize() override
|
||||
{
|
||||
for(auto *pTextContainer : m_vpTextContainers)
|
||||
{
|
||||
if(pTextContainer->m_ContainerIndex.Valid() && pTextContainer->m_ContainerIndex.m_UseCount.use_count() <= 1)
|
||||
{
|
||||
dbg_msg("textrender", "Found non empty text container with index %d with %d quads '%s'", pTextContainer->m_StringInfo.m_QuadBufferContainerIndex, (int)pTextContainer->m_StringInfo.m_QuadNum, pTextContainer->m_aDebugText);
|
||||
dbg_assert(false, "Text container was forgotten by the implementation (the index was overwritten).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnWindowResize() override
|
||||
{
|
||||
bool HasNonEmptyTextContainer = false;
|
||||
|
@ -1970,6 +1990,7 @@ public:
|
|||
if(pTextContainer->m_StringInfo.m_QuadBufferContainerIndex != -1)
|
||||
{
|
||||
dbg_msg("textrender", "Found non empty text container with index %d with %d quads '%s'", pTextContainer->m_StringInfo.m_QuadBufferContainerIndex, (int)pTextContainer->m_StringInfo.m_QuadNum, pTextContainer->m_aDebugText);
|
||||
dbg_msg("textrender", "The text container index was in use by %d ", (int)pTextContainer->m_ContainerIndex.m_UseCount.use_count());
|
||||
HasNonEmptyTextContainer = true; // NOLINT(clang-analyzer-deadcode.DeadStores)
|
||||
}
|
||||
dbg_assert(pTextContainer->m_StringInfo.m_DbgShadowBytes == STextString{}.m_DbgShadowBytes && pTextContainer->m_StringInfo.m_DbgShadowBytes2 == STextString{}.m_DbgShadowBytes2, "shadow bytes were modified in text container.");
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <engine/graphics.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -212,9 +213,16 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
struct STextContainerUsages
|
||||
{
|
||||
int m_Dummy = 0;
|
||||
};
|
||||
|
||||
struct STextContainerIndex
|
||||
{
|
||||
int m_Index;
|
||||
std::shared_ptr<STextContainerUsages> m_UseCount =
|
||||
std::make_shared<STextContainerUsages>(STextContainerUsages());
|
||||
|
||||
STextContainerIndex() { Reset(); }
|
||||
bool Valid() const { return m_Index >= 0; }
|
||||
|
@ -294,6 +302,7 @@ public:
|
|||
virtual ColorRGBA GetTextOutlineColor() const = 0;
|
||||
virtual ColorRGBA GetTextSelectionColor() const = 0;
|
||||
|
||||
virtual void OnPreWindowResize() = 0;
|
||||
virtual void OnWindowResize() = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -902,6 +902,8 @@ void CGameClient::OnFlagGrab(int TeamID)
|
|||
|
||||
void CGameClient::OnWindowResize()
|
||||
{
|
||||
TextRender()->OnPreWindowResize();
|
||||
|
||||
for(auto &pComponent : m_vpAll)
|
||||
pComponent->OnWindowResize();
|
||||
|
||||
|
|
Loading…
Reference in a new issue