mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Added size restrictions to fonts and textures to avoid crashes caused by invalid theme configuration.
This commit is contained in:
parent
cb8596ab8a
commit
91460495be
|
@ -124,11 +124,10 @@ void ImageComponent::resize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure sub-pixel values are not rounded to zero.
|
// Make sure sub-pixel values are not rounded to zero and that the size is not unreasonably
|
||||||
if (mSize.x < 1.0f)
|
// large (which may be caused by a mistake in the theme configuration).
|
||||||
mSize.x = 1.0f;
|
mSize.x = glm::clamp(mSize.x, 1.0f, mRenderer->getScreenWidth() * 2.0f);
|
||||||
if (mSize.y < 1.0f)
|
mSize.y = glm::clamp(mSize.y, 1.0f, mRenderer->getScreenHeight() * 2.0f);
|
||||||
mSize.y = 1.0f;
|
|
||||||
|
|
||||||
mTexture->rasterizeAt(mSize.x, mSize.y);
|
mTexture->rasterizeAt(mSize.x, mSize.y);
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,11 @@ void RatingComponent::setColorShift(unsigned int color)
|
||||||
|
|
||||||
void RatingComponent::onSizeChanged()
|
void RatingComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
|
// Make sure the size is not unreasonably large (which may be caused by a mistake in
|
||||||
|
// the theme configuration).
|
||||||
|
mSize.x = glm::clamp(mSize.x, 0.0f, mRenderer->getScreenWidth() / 2.0f);
|
||||||
|
mSize.y = glm::clamp(mSize.y, 0.0f, mRenderer->getScreenHeight() / 2.0f);
|
||||||
|
|
||||||
if (mSize.y == 0.0f)
|
if (mSize.y == 0.0f)
|
||||||
mSize.y = mSize.x / NUM_RATING_STARS;
|
mSize.y = mSize.x / NUM_RATING_STARS;
|
||||||
else if (mSize.x == 0.0f)
|
else if (mSize.x == 0.0f)
|
||||||
|
|
|
@ -160,6 +160,16 @@ Font::FontTexture::FontTexture(const int mSize)
|
||||||
// a texture buffer large enough to hold the fonts. This logic is obviously a hack though
|
// a texture buffer large enough to hold the fonts. This logic is obviously a hack though
|
||||||
// and needs to be properly reviewed and improved.
|
// and needs to be properly reviewed and improved.
|
||||||
textureSize = glm::ivec2 {mSize * (20 + extraTextureSize), mSize * (8 + extraTextureSize / 2)};
|
textureSize = glm::ivec2 {mSize * (20 + extraTextureSize), mSize * (8 + extraTextureSize / 2)};
|
||||||
|
|
||||||
|
// Make sure the size is not unreasonably large (which may be caused by a mistake in the
|
||||||
|
// theme configuration).
|
||||||
|
if (textureSize.x > static_cast<int>(Renderer::getScreenWidth()) * 10)
|
||||||
|
textureSize.x =
|
||||||
|
glm::clamp(textureSize.x, 0, static_cast<int>(Renderer::getScreenWidth()) * 10);
|
||||||
|
if (textureSize.y > static_cast<int>(Renderer::getScreenHeight()) * 10)
|
||||||
|
textureSize.y =
|
||||||
|
glm::clamp(textureSize.y, 0, static_cast<int>(Renderer::getScreenHeight()) * 10);
|
||||||
|
|
||||||
writePos = glm::ivec2 {0, 0};
|
writePos = glm::ivec2 {0, 0};
|
||||||
rowHeight = 0;
|
rowHeight = 0;
|
||||||
}
|
}
|
||||||
|
@ -755,8 +765,13 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
|
||||||
std::string path {orig ? orig->mPath : getDefaultPath()};
|
std::string path {orig ? orig->mPath : getDefaultPath()};
|
||||||
|
|
||||||
float sh {static_cast<float>(Renderer::getScreenHeight())};
|
float sh {static_cast<float>(Renderer::getScreenHeight())};
|
||||||
|
|
||||||
|
// Make sure the size is not unreasonably large (which may be caused by a mistake in the
|
||||||
|
// theme configuration).
|
||||||
if (properties & FONT_SIZE && elem->has("fontSize"))
|
if (properties & FONT_SIZE && elem->has("fontSize"))
|
||||||
size = static_cast<int>(sh * elem->get<float>("fontSize"));
|
size = glm::clamp(static_cast<int>(sh * elem->get<float>("fontSize")), 0,
|
||||||
|
static_cast<int>(Renderer::getInstance()->getScreenHeight()));
|
||||||
|
|
||||||
if (properties & FONT_PATH && elem->has("fontPath"))
|
if (properties & FONT_PATH && elem->has("fontPath"))
|
||||||
path = elem->get<std::string>("fontPath");
|
path = elem->get<std::string>("fontPath");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue