Fixed an issue where large text sizes at high resolutions would crash the application.

This commit is contained in:
Leon Styhre 2021-01-16 18:05:48 +01:00
parent 917ed738a0
commit 09e5095a08
4 changed files with 14 additions and 12 deletions

View file

@ -95,6 +95,7 @@ Many bugs have been fixed, and numerous features that were only partially implem
* If the user tried to enter a blank game name in the metadata editor, the application would crash upon saving * If the user tried to enter a blank game name in the metadata editor, the application would crash upon saving
* Switching to the Grid view style with a placeholder shown in the gamelist crashed the application * Switching to the Grid view style with a placeholder shown in the gamelist crashed the application
* FileSystemUtil::getDirContent crashed when searching through directories recursively * FileSystemUtil::getDirContent crashed when searching through directories recursively
* Large text sizes at higher resolutions (such as 4K) would crash the application as fixed-size texture buffers were used which weren't big enough to hold the larger font textures
* Fixed a massive memory leak related to SVG images * Fixed a massive memory leak related to SVG images
* Fixed an issue where SVG images would sometimes be cut off slightly on the right side (e.g. logos on the system view carousel) * Fixed an issue where SVG images would sometimes be cut off slightly on the right side (e.g. logos on the system view carousel)
* The scraper didn't handle error conditions correctly * The scraper didn't handle error conditions correctly

View file

@ -89,11 +89,11 @@ void SystemView::populate()
if (!e.data.logo) { if (!e.data.logo) {
// No logo in theme; use text. // No logo in theme; use text.
TextComponent* text = new TextComponent( TextComponent* text = new TextComponent(
mWindow, mWindow,
(*it)->getName(), (*it)->getName(),
Font::get(FONT_SIZE_LARGE), Font::get(FONT_SIZE_LARGE),
0x000000FF, 0x000000FF,
ALIGN_CENTER); ALIGN_CENTER);
text->setSize(mCarousel.logoSize * mCarousel.logoScale); text->setSize(mCarousel.logoSize * mCarousel.logoScale);
text->applyTheme((*it)->getTheme(), "system", "logoText", text->applyTheme((*it)->getTheme(), "system", "logoText",
ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR | ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR |

View file

@ -128,10 +128,12 @@ void Font::unloadTextures()
it->deinitTexture(); it->deinitTexture();
} }
Font::FontTexture::FontTexture() Font::FontTexture::FontTexture(const int mSize)
{ {
textureId = 0; textureId = 0;
textureSize = Vector2i(2048, 512); // I'm not entirely sure if the 16 and 4 constants are correct, but they seem to provide
// a texture buffer large enough to hold the fonts. (Otherwise the application would crash.)
textureSize = Vector2i(mSize * 16, mSize * 4);
writePos = Vector2i::Zero(); writePos = Vector2i::Zero();
rowHeight = 0; rowHeight = 0;
} }
@ -197,9 +199,8 @@ void Font::getTextureForNewGlyph(const Vector2i& glyphSize,
return; // Yes. return; // Yes.
} }
// Current textures are full, // Current textures are full, make a new one.
// make a new one. mTextures.push_back(FontTexture(mSize));
mTextures.push_back(FontTexture());
tex_out = &mTextures.back(); tex_out = &mTextures.back();
tex_out->initTexture(); tex_out->initTexture();
@ -607,7 +608,7 @@ TextCache* Font::buildTextCache(
convertedColor }; convertedColor };
// Round vertices. // Round vertices.
for (int i = 1; i < 5; ++i) for (int i = 1; i < 5; i++)
vertices[i].pos.round(); vertices[i].pos.round();
// Make duplicates of first and last vertex so this can be rendered as a triangle strip. // Make duplicates of first and last vertex so this can be rendered as a triangle strip.

View file

@ -106,7 +106,7 @@ private:
Vector2i writePos; Vector2i writePos;
int rowHeight; int rowHeight;
FontTexture(); FontTexture(const int mSize);
~FontTexture(); ~FontTexture();
bool findEmpty(const Vector2i& size, Vector2i& cursor_out); bool findEmpty(const Vector2i& size, Vector2i& cursor_out);