Fix client crash when starting without font file

Add checks to text render functions to prevent crashes when no default font is set.
This commit is contained in:
Robert Müller 2023-04-05 21:47:49 +02:00
parent 5db9f029e4
commit d203f38f01

View file

@ -1714,6 +1714,8 @@ public:
void UploadEntityLayerText(void *pTexBuff, size_t ImageColorChannelCount, int TexWidth, int TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) override
{
if(m_pDefaultFont == nullptr)
return;
if(FontSize < 1)
return;
@ -1796,6 +1798,9 @@ public:
float GetGlyphOffsetX(int FontSize, char TextCharacter) const override
{
if(m_pDefaultFont == nullptr)
return -1;
const CFont *pFont = m_pDefaultFont;
FT_Set_Pixel_Sizes(pFont->m_FtFace, 0, FontSize);
const char *pTmp = &TextCharacter;
@ -1821,6 +1826,9 @@ public:
int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) const override
{
if(m_pDefaultFont == nullptr)
return 0;
const CFont *pFont = m_pDefaultFont;
const char *pCurrent = pText;
const char *pEnd = pCurrent + TextLength;