mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Fixed an issue where a double free in GuiLaunchScreen could cause an unclean application shutdown
This commit is contained in:
parent
599cb7c7a0
commit
e19fbff692
|
|
@ -17,10 +17,11 @@
|
||||||
|
|
||||||
GuiLaunchScreen::GuiLaunchScreen()
|
GuiLaunchScreen::GuiLaunchScreen()
|
||||||
: mRenderer {Renderer::getInstance()}
|
: mRenderer {Renderer::getInstance()}
|
||||||
, mGrid {nullptr}
|
, mGrid {glm::ivec2 {3, 8}}
|
||||||
, mMarquee {nullptr}
|
, mMarquee {nullptr}
|
||||||
{
|
{
|
||||||
addChild(&mBackground);
|
addChild(&mBackground);
|
||||||
|
addChild(&mGrid);
|
||||||
mWindow->setLaunchScreen(this);
|
mWindow->setLaunchScreen(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,9 +33,6 @@ GuiLaunchScreen::~GuiLaunchScreen()
|
||||||
|
|
||||||
void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
{
|
{
|
||||||
mGrid = new ComponentGrid(glm::ivec2 {3, 8});
|
|
||||||
addChild(mGrid);
|
|
||||||
|
|
||||||
mImagePath = game->getMarqueePath();
|
mImagePath = game->getMarqueePath();
|
||||||
|
|
||||||
// We need to unload the image first as it may be cached at a modified resolution
|
// We need to unload the image first as it may be cached at a modified resolution
|
||||||
|
|
@ -50,8 +48,8 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
const float gameNameFontSize {0.073f};
|
const float gameNameFontSize {0.073f};
|
||||||
|
|
||||||
// Spacer row.
|
// Spacer row.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 0}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 0}, false, false,
|
||||||
glm::ivec2 {1, 1});
|
glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Title.
|
// Title.
|
||||||
mTitle = std::make_shared<TextComponent>(
|
mTitle = std::make_shared<TextComponent>(
|
||||||
|
|
@ -59,19 +57,19 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
Font::get(titleFontSize *
|
Font::get(titleFontSize *
|
||||||
std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())),
|
std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())),
|
||||||
mMenuColorTertiary, ALIGN_CENTER);
|
mMenuColorTertiary, ALIGN_CENTER);
|
||||||
mGrid->setEntry(mTitle, glm::ivec2 {1, 1}, false, true, glm::ivec2 {1, 1});
|
mGrid.setEntry(mTitle, glm::ivec2 {1, 1}, false, true, glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Spacer row.
|
// Spacer row.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 2}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 2}, false, false,
|
||||||
glm::ivec2 {1, 1});
|
glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Row for the marquee.
|
// Row for the marquee.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 3}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 3}, false, false,
|
||||||
glm::ivec2 {1, 1});
|
glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Spacer row.
|
// Spacer row.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 4}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 4}, false, false,
|
||||||
glm::ivec2 {1, 1});
|
glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Game name.
|
// Game name.
|
||||||
mGameName = std::make_shared<TextComponent>(
|
mGameName = std::make_shared<TextComponent>(
|
||||||
|
|
@ -79,24 +77,24 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
Font::get(gameNameFontSize *
|
Font::get(gameNameFontSize *
|
||||||
std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())),
|
std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())),
|
||||||
mMenuColorTitle, ALIGN_CENTER);
|
mMenuColorTitle, ALIGN_CENTER);
|
||||||
mGrid->setEntry(mGameName, glm::ivec2 {1, 5}, false, true, glm::ivec2 {1, 1});
|
mGrid.setEntry(mGameName, glm::ivec2 {1, 5}, false, true, glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// System name.
|
// System name.
|
||||||
mSystemName = std::make_shared<TextComponent>("SYSTEM NAME", Font::get(FONT_SIZE_MEDIUM),
|
mSystemName = std::make_shared<TextComponent>("SYSTEM NAME", Font::get(FONT_SIZE_MEDIUM),
|
||||||
mMenuColorTertiary, ALIGN_CENTER);
|
mMenuColorTertiary, ALIGN_CENTER);
|
||||||
mGrid->setEntry(mSystemName, glm::ivec2 {1, 6}, false, true, glm::ivec2 {1, 1});
|
mGrid.setEntry(mSystemName, glm::ivec2 {1, 6}, false, true, glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Spacer row.
|
// Spacer row.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 7}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {1, 7}, false, false,
|
||||||
glm::ivec2 {1, 1});
|
glm::ivec2 {1, 1});
|
||||||
|
|
||||||
// Left spacer.
|
// Left spacer.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {0, 0}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {0, 0}, false, false,
|
||||||
glm::ivec2 {1, 8});
|
glm::ivec2 {1, 8});
|
||||||
|
|
||||||
// Right spacer.
|
// Right spacer.
|
||||||
mGrid->setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {2, 0}, false, false,
|
mGrid.setEntry(std::make_shared<GuiComponent>(), glm::ivec2 {2, 0}, false, false,
|
||||||
glm::ivec2 {1, 8});
|
glm::ivec2 {1, 8});
|
||||||
|
|
||||||
// Adjust the width depending on the aspect ratio of the screen, to make the screen look
|
// Adjust the width depending on the aspect ratio of the screen, to make the screen look
|
||||||
// somewhat coherent regardless of screen type. The 1.778 aspect ratio value is the 16:9
|
// somewhat coherent regardless of screen type. The 1.778 aspect ratio value is the 16:9
|
||||||
|
|
@ -135,30 +133,30 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
|
|
||||||
// Set row heights.
|
// Set row heights.
|
||||||
if (mImagePath != "")
|
if (mImagePath != "")
|
||||||
mGrid->setRowHeightPerc(0, 0.09f, false);
|
mGrid.setRowHeightPerc(0, 0.09f, false);
|
||||||
else
|
else
|
||||||
mGrid->setRowHeightPerc(0, 0.15f, false);
|
mGrid.setRowHeightPerc(0, 0.15f, false);
|
||||||
mGrid->setRowHeightPerc(1, mTitle->getFont()->getLetterHeight() * 1.70f / mSize.y, false);
|
mGrid.setRowHeightPerc(1, mTitle->getFont()->getLetterHeight() * 1.70f / mSize.y, false);
|
||||||
mGrid->setRowHeightPerc(2, 0.05f, false);
|
mGrid.setRowHeightPerc(2, 0.05f, false);
|
||||||
if (mImagePath != "")
|
if (mImagePath != "")
|
||||||
mGrid->setRowHeightPerc(3, 0.35f, false);
|
mGrid.setRowHeightPerc(3, 0.35f, false);
|
||||||
else
|
else
|
||||||
mGrid->setRowHeightPerc(3, 0.01f, false);
|
mGrid.setRowHeightPerc(3, 0.01f, false);
|
||||||
mGrid->setRowHeightPerc(4, 0.05f, false);
|
mGrid.setRowHeightPerc(4, 0.05f, false);
|
||||||
mGrid->setRowHeightPerc(5, mGameName->getFont()->getHeight() * 0.80f / mSize.y, false);
|
mGrid.setRowHeightPerc(5, mGameName->getFont()->getHeight() * 0.80f / mSize.y, false);
|
||||||
mGrid->setRowHeightPerc(6, mSystemName->getFont()->getHeight() * 0.90f / mSize.y, false);
|
mGrid.setRowHeightPerc(6, mSystemName->getFont()->getHeight() * 0.90f / mSize.y, false);
|
||||||
|
|
||||||
// Set left and right spacers column widths.
|
// Set left and right spacers column widths.
|
||||||
mGrid->setColWidthPerc(0, 0.025f);
|
mGrid.setColWidthPerc(0, 0.025f);
|
||||||
mGrid->setColWidthPerc(2, 0.025f);
|
mGrid.setColWidthPerc(2, 0.025f);
|
||||||
|
|
||||||
mGrid->setSize(mSize);
|
mGrid.setSize(mSize);
|
||||||
|
|
||||||
float totalRowHeight {0.0f};
|
float totalRowHeight {0.0f};
|
||||||
|
|
||||||
// Hack to adjust the window height to the row boundary.
|
// Hack to adjust the window height to the row boundary.
|
||||||
for (int i = 0; i < 7; ++i)
|
for (int i {0}; i < 7; ++i)
|
||||||
totalRowHeight += mGrid->getRowHeight(i);
|
totalRowHeight += mGrid.getRowHeight(i);
|
||||||
|
|
||||||
setSize(mSize.x, totalRowHeight);
|
setSize(mSize.x, totalRowHeight);
|
||||||
|
|
||||||
|
|
@ -176,15 +174,15 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
mMarquee->cropTransparentPadding(
|
mMarquee->cropTransparentPadding(
|
||||||
mRenderer->getScreenWidth() *
|
mRenderer->getScreenWidth() *
|
||||||
(multiplier * (1.778f / mRenderer->getScreenAspectRatio())),
|
(multiplier * (1.778f / mRenderer->getScreenAspectRatio())),
|
||||||
mGrid->getRowHeight(3));
|
mGrid.getRowHeight(3));
|
||||||
|
|
||||||
mMarquee->setOrigin(0.5f, 0.5f);
|
mMarquee->setOrigin(0.5f, 0.5f);
|
||||||
glm::vec3 currentPos {mMarquee->getPosition()};
|
glm::vec3 currentPos {mMarquee->getPosition()};
|
||||||
|
|
||||||
// Position the image in the middle of row four.
|
// Position the image in the middle of row four.
|
||||||
currentPos.x = mSize.x / 2.0f;
|
currentPos.x = mSize.x / 2.0f;
|
||||||
currentPos.y = mGrid->getRowHeight(0) + mGrid->getRowHeight(1) + mGrid->getRowHeight(2) +
|
currentPos.y = mGrid.getRowHeight(0) + mGrid.getRowHeight(1) + mGrid.getRowHeight(2) +
|
||||||
mGrid->getRowHeight(3) / 2.0f;
|
mGrid.getRowHeight(3) / 2.0f;
|
||||||
mMarquee->setPosition(currentPos);
|
mMarquee->setPosition(currentPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,10 +197,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
|
||||||
|
|
||||||
void GuiLaunchScreen::closeLaunchScreen()
|
void GuiLaunchScreen::closeLaunchScreen()
|
||||||
{
|
{
|
||||||
if (mGrid) {
|
mGrid.clearChildren();
|
||||||
delete mGrid;
|
|
||||||
mGrid = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mMarquee) {
|
if (mMarquee) {
|
||||||
delete mMarquee;
|
delete mMarquee;
|
||||||
|
|
@ -219,7 +214,7 @@ void GuiLaunchScreen::closeLaunchScreen()
|
||||||
void GuiLaunchScreen::onSizeChanged()
|
void GuiLaunchScreen::onSizeChanged()
|
||||||
{
|
{
|
||||||
// Update mGrid size.
|
// Update mGrid size.
|
||||||
mGrid->setSize(mSize);
|
mGrid.setSize(mSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiLaunchScreen::update(int deltaTime)
|
void GuiLaunchScreen::update(int deltaTime)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public:
|
||||||
private:
|
private:
|
||||||
Renderer* mRenderer;
|
Renderer* mRenderer;
|
||||||
BackgroundComponent mBackground;
|
BackgroundComponent mBackground;
|
||||||
ComponentGrid* mGrid;
|
ComponentGrid mGrid;
|
||||||
|
|
||||||
std::shared_ptr<TextComponent> mTitle;
|
std::shared_ptr<TextComponent> mTitle;
|
||||||
std::shared_ptr<TextComponent> mGameName;
|
std::shared_ptr<TextComponent> mGameName;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue