TTF_OpenFontRW retains the SDL_RWops on success, so we must keep the font data around to back it

This commit is contained in:
Cameron Gutman
2019-04-09 21:26:47 -07:00
parent a8dc5ac14a
commit 6783cf57da
2 changed files with 7 additions and 5 deletions

View File

@@ -9,7 +9,8 @@
SdlRenderer::SdlRenderer()
: m_Renderer(nullptr),
m_Texture(nullptr)
m_Texture(nullptr),
m_FontData(Path::readDataFile("ModeSeven.ttf"))
{
SDL_assert(TTF_WasInit() == 0);
if (TTF_Init() != 0) {
@@ -88,14 +89,14 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
{
// Construct the required font to render the overlay
if (m_OverlayFonts[type] == nullptr) {
QByteArray fontData = Path::readDataFile("ModeSeven.ttf");
if (fontData.isEmpty()) {
if (m_FontData.isEmpty()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Unable to load SDL overlay font");
"SDL overlay font failed to load");
return;
}
m_OverlayFonts[type] = TTF_OpenFontRW(SDL_RWFromConstMem(fontData.constData(), fontData.size()),
// m_FontData must stay around until the font is closed
m_OverlayFonts[type] = TTF_OpenFontRW(SDL_RWFromConstMem(m_FontData.constData(), m_FontData.size()),
1,
Session::get()->getOverlayManager().getOverlayFontSize(type));
if (m_OverlayFonts[type] == nullptr) {

View File

@@ -26,6 +26,7 @@ private:
SDL_Renderer* m_Renderer;
SDL_Texture* m_Texture;
QByteArray m_FontData;
TTF_Font* m_OverlayFonts[Overlay::OverlayMax];
SDL_Surface* m_OverlaySurfaces[Overlay::OverlayMax];
SDL_Texture* m_OverlayTextures[Overlay::OverlayMax];