mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #6497
6497: Fix client crash/hang when launching without data directory r=edg-l a=Robyt3 Closes #4638. ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [X] Considered possible null pointers and out of bounds array indexing - [X] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
ada7c4d597
|
@ -1716,6 +1716,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;
|
||||
|
||||
|
@ -1798,6 +1800,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;
|
||||
|
@ -1823,6 +1828,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;
|
||||
|
|
|
@ -230,11 +230,14 @@ void CMenuBackground::LoadMenuBackground(bool HasDayHint, bool HasNightHint)
|
|||
}
|
||||
else if(str_comp(pMenuMap, "rand") == 0)
|
||||
{
|
||||
//make sure to load themes
|
||||
std::vector<CTheme> &vThemesRef = GetThemes();
|
||||
int RandomThemeIndex = rand() % (vThemesRef.size() - PREDEFINED_THEMES_COUNT);
|
||||
if(RandomThemeIndex + PREDEFINED_THEMES_COUNT < (int)vThemesRef.size())
|
||||
pMenuMap = vThemesRef[RandomThemeIndex + PREDEFINED_THEMES_COUNT].m_Name.c_str();
|
||||
// make sure to load themes
|
||||
const std::vector<CTheme> &vThemesRef = GetThemes();
|
||||
if(vThemesRef.size() > PREDEFINED_THEMES_COUNT)
|
||||
{
|
||||
int RandomThemeIndex = rand() % (vThemesRef.size() - PREDEFINED_THEMES_COUNT);
|
||||
if(RandomThemeIndex + PREDEFINED_THEMES_COUNT < (int)vThemesRef.size())
|
||||
pMenuMap = vThemesRef[RandomThemeIndex + PREDEFINED_THEMES_COUNT].m_Name.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
char aBuf[128];
|
||||
|
|
|
@ -148,6 +148,14 @@ void CLocalizationDatabase::LoadIndexfile(IStorage *pStorage, IConsole *pConsole
|
|||
|
||||
void CLocalizationDatabase::SelectDefaultLanguage(IConsole *pConsole, char *pFilename, size_t Length) const
|
||||
{
|
||||
if(Languages().empty())
|
||||
return;
|
||||
if(Languages().size() == 1)
|
||||
{
|
||||
str_copy(pFilename, Languages()[0].m_FileName.c_str(), Length);
|
||||
return;
|
||||
}
|
||||
|
||||
char aLocaleStr[128];
|
||||
os_locale_str(aLocaleStr, sizeof(aLocaleStr));
|
||||
|
||||
|
@ -194,7 +202,7 @@ void CLocalizationDatabase::SelectDefaultLanguage(IConsole *pConsole, char *pFil
|
|||
}
|
||||
|
||||
// Stop if no more locale segments are left
|
||||
if(i == 0)
|
||||
if(i <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue