Skip to content

Commit

Permalink
Fix crashes when GetClientColor returns null in CTF
Browse files Browse the repository at this point in the history
Resolves #68
  • Loading branch information
SamVanheer committed May 8, 2022
1 parent 0490808 commit 6bd0ac7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
9 changes: 9 additions & 0 deletions cl_dll/hud_spectator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ extern Vector v_angles; // last view angle
extern Vector v_cl_angles; // last client/mouse angle
extern Vector v_sim_org; // last sim origin

//Same color as in TeamFortressViewport::UpdateSpectatorPanel
float DefaultPlayerColor[3] = {143 / 255.f, 143 / 255.f, 54 / 255.f};

#if 0
const char *GetSpectatorLabel ( int iMode )
{
Expand Down Expand Up @@ -661,6 +664,12 @@ bool CHudSpectator::Draw(float flTime)

color = GetClientColor(i + 1);

//TODO: this is pretty ugly, need a better way.
if (!color)
{
color = DefaultPlayerColor;
}

// draw the players name and health underneath
sprintf(string, "%s", g_PlayerInfoList[i + 1].name);

Expand Down
24 changes: 17 additions & 7 deletions cl_dll/vgui_TeamFortressViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,19 +1354,29 @@ void TeamFortressViewport::UpdateSpectatorPanel()
pBottomText = CHudTextMessage::BufferedLocaliseTextString(bottomText);
}

bool useTeamColor = false;

// in first person mode colorize player names
if ((g_iUser1 == OBS_IN_EYE) && 0 != player)
{
float* color = GetClientColor(player);
int r = color[0] * 255;
int g = color[1] * 255;
int b = color[2] * 255;

// set team color, a bit transparent
m_pSpectatorPanel->m_BottomMainLabel->setFgColor(r, g, b, 0);
m_pSpectatorPanel->m_BottomMainButton->setFgColor(r, g, b, 0);
//Color is null in CTF.
if (color)
{
int r = color[0] * 255;
int g = color[1] * 255;
int b = color[2] * 255;

// set team color, a bit transparent
m_pSpectatorPanel->m_BottomMainLabel->setFgColor(r, g, b, 0);
m_pSpectatorPanel->m_BottomMainButton->setFgColor(r, g, b, 0);

useTeamColor = true;
}
}
else

if (!useTeamColor)
{ // restore GUI color
m_pSpectatorPanel->m_BottomMainLabel->setFgColor(143, 143, 54, 0);
m_pSpectatorPanel->m_BottomMainButton->setFgColor(143, 143, 54, 0);
Expand Down

0 comments on commit 6bd0ac7

Please sign in to comment.