Skip to content

Commit df9d47d

Browse files
committed
Use shared_ptr
1 parent 489eb7b commit df9d47d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Client/mods/deathmatch/logic/CClientVectorGraphic.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CClientVectorGraphic::CClientVectorGraphic(CClientManager* pManager, ElementID I
1818

1919
m_pManager = pManager;
2020

21-
m_pVectorGraphicDisplay = new CClientVectorGraphicDisplay(m_pManager->GetDisplayManager(), this);
21+
m_pVectorGraphicDisplay = std::make_shared<CClientVectorGraphicDisplay>(m_pManager->GetDisplayManager(), this);
2222

2323
// Generate the default XML document
2424
SString defaultXmlString = SString("<svg viewBox='0 0 %u %u'></svg>", pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY);
@@ -46,7 +46,7 @@ bool CClientVectorGraphic::LoadFromString(std::string strData)
4646

4747
bool CClientVectorGraphic::SetDocument(CXMLNode* node)
4848
{
49-
if (!node || !node->IsValid())
49+
if (!m_pVectorGraphicDisplay || !node || !node->IsValid())
5050
return false;
5151

5252
if (m_pXMLString && m_pXMLString->node != node)
@@ -80,6 +80,9 @@ bool CClientVectorGraphic::RemoveUpdateCallback()
8080

8181
void CClientVectorGraphic::OnUpdate()
8282
{
83+
if (!m_pVectorGraphicDisplay)
84+
return;
85+
8386
m_pVectorGraphicDisplay->UpdateTexture();
8487

8588
if (std::holds_alternative<CLuaFunctionRef>(m_updateCallbackRef))

Client/mods/deathmatch/logic/CClientVectorGraphic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CClientVectorGraphic final : public CClientTexture
3636
lunasvg::Document* GetSVGDocument() const { return m_pSVGDocument.get(); }
3737
CXMLNode* GetXMLDocument() const { return m_pXMLDocument; }
3838

39-
CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay; }
39+
CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay.get(); }
4040

4141
bool IsDisplayCleared() const { return m_pVectorGraphicDisplay->IsCleared(); }
4242
bool IsDestroyed() const { return m_bIsDestroyed; }
@@ -57,7 +57,7 @@ class CClientVectorGraphic final : public CClientTexture
5757
std::unique_ptr<SXMLString> m_pXMLString = nullptr;
5858
CXMLNode* m_pXMLDocument = nullptr;
5959

60-
CClientVectorGraphicDisplay* m_pVectorGraphicDisplay;
60+
std::shared_ptr<CClientVectorGraphicDisplay> m_pVectorGraphicDisplay;
6161

6262
std::variant<CLuaFunctionRef, bool> m_updateCallbackRef = false;
6363

0 commit comments

Comments
 (0)