diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 179c0b0d4..efdf2cf86 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -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; diff --git a/src/game/client/components/menu_background.cpp b/src/game/client/components/menu_background.cpp index 8506b40a8..a3b539c8c 100644 --- a/src/game/client/components/menu_background.cpp +++ b/src/game/client/components/menu_background.cpp @@ -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 &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 &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]; diff --git a/src/game/localization.cpp b/src/game/localization.cpp index 6092cf607..fb74ae879 100644 --- a/src/game/localization.cpp +++ b/src/game/localization.cpp @@ -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; } }