Skip to content

Commit

Permalink
Fix crash around m_pGameEvent + gHUD
Browse files Browse the repository at this point in the history
* Instead use rain's suggestion to change it to using
  `DECLARE_HUDELEMENT` directly
  • Loading branch information
nullsystem committed Jun 2, 2024
1 parent 15725ad commit f8d8fdb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 26 deletions.
7 changes: 4 additions & 3 deletions mp/src/game/client/neo/c_neo_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void C_NEO_Player::PreThink( void )
Warning("Couldn't find ghostMarker\n");
}

auto indicator = m_pNeoPanel->GetGameEventIndicator();
auto indicator = GET_HUDELEMENT(CNEOHud_GameEvent);

if (indicator)
{
Expand Down Expand Up @@ -970,9 +970,10 @@ void C_NEO_Player::PostThink(void)

if (!preparingToHideMsg && m_bPreviouslyPreparingToHideMsg)
{
if (m_pNeoPanel && m_pNeoPanel->GetGameEventIndicator())
auto indicator = GET_HUDELEMENT(CNEOHud_GameEvent);
if (indicator)
{
m_pNeoPanel->GetGameEventIndicator()->SetVisible(false);
indicator->SetVisible(false);
m_bPreviouslyPreparingToHideMsg = false;
}
else
Expand Down
15 changes: 0 additions & 15 deletions mp/src/game/client/neo/ui/neo_hud_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ CNeoHudElements::CNeoHudElements(IViewPort *pViewPort)
m_pAmmo = NULL;
m_pCompass = NULL;
m_pFriendlyMarker = NULL;
m_pGameEvent = NULL;
m_pHTA = NULL;
m_pRoundState = NULL;
m_pLastUpdater = NULL;
Expand Down Expand Up @@ -91,13 +90,6 @@ void CNeoHudElements::FreePanelChildren()
m_pFriendlyMarker = NULL;
}

// now that the game event hud is added to gHud, gHud should take care of deleting it itself?
if (m_pGameEvent)
{
m_pGameEvent->DeletePanel();
m_pGameEvent = NULL;
}

if (m_pHTA)
{
m_pHTA->DeletePanel();
Expand Down Expand Up @@ -243,7 +235,6 @@ void CNeoHudElements::InitHud()
InitAmmo();
InitCompass();
InitFriendlyMarker();
InitGameEventIndicator();
InitGhostMarkers();
InitHTA();
InitRoundState();
Expand Down Expand Up @@ -275,12 +266,6 @@ void CNeoHudElements::InitFriendlyMarker()
m_pFriendlyMarker = new CNEOHud_FriendlyMarker(UI_ELEMENT_NAME_IFF, this);
}

void CNeoHudElements::InitGameEventIndicator()
{
Assert(!m_pGameEvent);
m_pGameEvent = new CNEOHud_GameEvent(UI_ELEMENT_GAME_EVENT, this);
}

void CNeoHudElements::InitGhostMarkers()
{
Assert(m_vecGhostMarkers.Count() == 0);
Expand Down
5 changes: 1 addition & 4 deletions mp/src/game/client/neo/ui/neo_hud_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CNeoHudElements : public vgui::EditablePanel,

CNEOHud_Ammo* GetAmmo() { return m_pAmmo; }
CNEOHud_Compass *GetCompass() { return m_pCompass; }
CNEOHud_GameEvent *GetGameEventIndicator() { return m_pGameEvent; }
CNEOHud_GhostMarker *GetGhostMarker();
CNEOHud_HTA* GetHTA() { return m_pHTA; }
CNEOHud_FriendlyMarker *GetIFF() { return m_pFriendlyMarker; }
Expand All @@ -77,7 +76,6 @@ class CNeoHudElements : public vgui::EditablePanel,
private:
void InitAmmo();
void InitCompass();
void InitGameEventIndicator();
void InitGhostMarkers();
void InitFriendlyMarker();
void InitHTA();
Expand All @@ -94,7 +92,6 @@ class CNeoHudElements : public vgui::EditablePanel,
CNEOHud_Ammo* m_pAmmo;
CNEOHud_Compass *m_pCompass;
CNEOHud_FriendlyMarker *m_pFriendlyMarker;
CNEOHud_GameEvent *m_pGameEvent;
CNEOHud_HTA* m_pHTA;
CNEOHud_RoundState *m_pRoundState;
CTargetID* m_pTargetID;
Expand All @@ -107,4 +104,4 @@ class CNeoHudElements : public vgui::EditablePanel,
void FillIFFs();
};

#endif // NEO_HUD_ELEMENTS_H
#endif // NEO_HUD_ELEMENTS_H
4 changes: 2 additions & 2 deletions mp/src/game/client/neo/ui/neo_hud_game_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using vgui::surface;

DECLARE_HUDELEMENT(CNEOHud_GameEvent);

NEO_HUD_ELEMENT_DECLARE_FREQ_CVAR(GameEvent, 0.1)

DECLARE_HUD_MESSAGE(CNEOHud_GameEvent, RoundResult);
Expand Down Expand Up @@ -61,8 +63,6 @@ CNEOHud_GameEvent::CNEOHud_GameEvent(const char *pElementName, vgui::Panel *pare

m_hFont = scheme->GetFont("NHudOCR");

gHUD.AddHudElement(this);

SetMessage("", 1);

SetVisible(false);
Expand Down
4 changes: 2 additions & 2 deletions mp/src/game/client/neo/ui/neo_hud_game_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CNEOHud_GameEvent : public CNEOHud_ChildElement, public CHudElement, publi
{
DECLARE_CLASS_SIMPLE(CNEOHud_GameEvent, vgui::Panel);
public:
CNEOHud_GameEvent(const char *pElementName, vgui::Panel *parent);
CNEOHud_GameEvent(const char *pElementName, vgui::Panel *parent = nullptr);

void SetMessage(const char *message, size_t size);
void SetMessage(const wchar_t *message, size_t size);
Expand Down Expand Up @@ -50,4 +50,4 @@ class CNEOHud_GameEvent : public CNEOHud_ChildElement, public CHudElement, publi
};


#endif // NEO_HUD_GAME_EVENT_H
#endif // NEO_HUD_GAME_EVENT_H

0 comments on commit f8d8fdb

Please sign in to comment.