Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

[WSOD fix] Merge https://github.com/RetroPie/EmulationStation/pull/88 #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix : Background musics are now played randomly
- Added custom favorites icons for each system
- Only save changed metadata when saving gamelist.xml (improve shutdown time)
- White Screen of Death fix by adding user-configurable VRAM usage limit

### Added
- Favorites as boolean in metadata
Expand Down
12 changes: 4 additions & 8 deletions es-app/src/components/RatingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Renderer.h"
#include "Window.h"
#include "Util.h"
#include "resources/SVGResource.h"

RatingComponent::RatingComponent(Window* window) : GuiComponent(window)
{
Expand Down Expand Up @@ -45,16 +44,13 @@ void RatingComponent::onSizeChanged()
else if(mSize.x() == 0)
mSize[0] = mSize.y() * NUM_RATING_STARS;

auto filledSVG = dynamic_cast<SVGResource*>(mFilledTexture.get());
auto unfilledSVG = dynamic_cast<SVGResource*>(mUnfilledTexture.get());

if(mSize.y() > 0)
{
size_t heightPx = (size_t)round(mSize.y());
if(filledSVG)
filledSVG->rasterizeAt(heightPx, heightPx);
if(unfilledSVG)
unfilledSVG->rasterizeAt(heightPx, heightPx);
if (mFilledTexture)
mFilledTexture->rasterizeAt(heightPx, heightPx);
if(mUnfilledTexture)
mUnfilledTexture->rasterizeAt(heightPx, heightPx);
}

updateVertices();
Expand Down
6 changes: 6 additions & 0 deletions es-app/src/guis/GuiMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ GuiMenu::GuiMenu(Window *window) : GuiComponent(window), mMenu(window, _("MAIN M
});
}

// maximum vram
auto max_vram = std::make_shared<SliderComponent>(mWindow, 0.f, 1000.f, 10.f, "Mb");
max_vram->setValue((float)(Settings::getInstance()->getInt("MaxVRAM")));
s->addWithLabel("VRAM LIMIT", max_vram);
s->addSaveFunc([max_vram] { Settings::getInstance()->setInt("MaxVRAM", (int)round(max_vram->getValue())); });

mWindow->pushGui(s);
});
}
Expand Down
5 changes: 5 additions & 0 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
}else if(strcmp(argv[i], "--scrape") == 0)
{
scrape_cmdline = true;
}else if(strcmp(argv[i], "--max-vram") == 0)
{
int maxVRAM = atoi(argv[i + 1]);
Settings::getInstance()->setInt("MaxVRAM", maxVRAM);
}else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
{
#ifdef WIN32
Expand All @@ -111,6 +115,7 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height
"--scrape scrape using command line interface\n"
"--windowed not fullscreen, should be used with --resolution\n"
"--vsync [1/on or 0/off] turn vsync on or off (default is on)\n"
"--max-vram [size] Max VRAM to use in Mb before swapping. 0 for unlimited\n"
"--help, -h summon a sentient, angry tuba\n\n"
"More information available in README.md.\n";
return false; //exit after printing help
Expand Down
4 changes: 2 additions & 2 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ void SystemView::addSystem(SystemData * it){
// make logo
if(theme->getElement("system", "logo", "image"))
{
ImageComponent* logo = new ImageComponent(mWindow);
ImageComponent* logo = new ImageComponent(mWindow, false, false);
logo->setMaxSize(Eigen::Vector2f(logoSize().x(), logoSize().y()));
logo->applyTheme((it)->getTheme(), "system", "logo", ThemeFlags::PATH);
logo->setPosition((logoSize().x() - logo->getSize().x()) / 2, (logoSize().y() - logo->getSize().y()) / 2); // center
e.data.logo = std::shared_ptr<GuiComponent>(logo);

ImageComponent* logoSelected = new ImageComponent(mWindow);
ImageComponent* logoSelected = new ImageComponent(mWindow, false, false);
logoSelected->setMaxSize(Eigen::Vector2f(logoSize().x() * SELECTED_SCALE, logoSize().y() * SELECTED_SCALE * 0.70f));
logoSelected->applyTheme((it)->getTheme(), "system", "logo", ThemeFlags::PATH);
logoSelected->setPosition((logoSize().x() - logoSelected->getSize().x()) / 2,
Expand Down
4 changes: 3 additions & 1 deletion es-app/src/views/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ void ViewController::reloadAll()
mCurrentView = getGameListView(mState.getSystem());
}else if(mState.viewing == SYSTEM_SELECT)
{
mSystemListView->goToSystem(mState.getSystem(), false);
SystemData* system = mState.getSystem();
goToSystemView(SystemData::sSystemVector.front());
mSystemListView->goToSystem(system, false);
mCurrentView = mSystemListView;
}else{
goToSystemView(SystemData::sSystemVector.front());
Expand Down
6 changes: 4 additions & 2 deletions es-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ set(CORE_HEADERS
# Resources
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/SVGResource.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureDataManager.h

# Embedded assets (needed by ResourceManager)
${emulationstation-all_SOURCE_DIR}/data/Resources.h
Expand Down Expand Up @@ -113,8 +114,9 @@ set(CORE_SOURCES
# Resources
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/SVGResource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureDataManager.cpp
)

set(EMBEDDED_ASSET_SOURCES
Expand Down
1 change: 1 addition & 0 deletions es-core/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void Settings::setDefaults() {
mIntMap["ScraperResizeWidth"] = 400;
mIntMap["ScraperResizeHeight"] = 0;
mIntMap["SystemVolume"] = 96;
mIntMap["MaxVRAM"] = 100;

mStringMap["TransitionStyle"] = "fade";
mStringMap["ThemeSet"] = "";
Expand Down
9 changes: 5 additions & 4 deletions es-core/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ void Window::update(int deltaTime)
ss << std::fixed << std::setprecision(2) << ((float)mFrameTimeElapsed / (float)mFrameCountElapsed) << "ms";

// vram
float textureVramUsageMb = TextureResource::getTotalMemUsage() / 1000.0f / 1000.0f;;
float textureVramUsageMb = TextureResource::getTotalMemUsage() / 1000.0f / 1000.0f;
float textureTotalUsageMb = TextureResource::getTotalTextureSize() / 1000.0f / 1000.0f;
float fontVramUsageMb = Font::getTotalMemUsage() / 1000.0f / 1000.0f;;
float totalVramUsageMb = textureVramUsageMb + fontVramUsageMb;
ss << "\nVRAM: " << totalVramUsageMb << "mb (texs: " << textureVramUsageMb << "mb, fonts: " << fontVramUsageMb << "mb)";

ss << "\nFont VRAM: " << fontVramUsageMb << " Tex VRAM: " << textureVramUsageMb <<
" Tex Max: " << textureTotalUsageMb;
mFrameDataText = std::unique_ptr<TextCache>(mDefaultFonts.at(1)->buildTextCache(ss.str(), 50.f, 50.f, 0xFF00FFFF));
}

Expand Down Expand Up @@ -267,7 +268,7 @@ void Window::renderWaitingScreen(const std::string& text)
Renderer::setMatrix(trans);
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFFFF);

ImageComponent splash(this);
ImageComponent splash(this, true);
splash.setResize(Renderer::getScreenWidth() * 0.6f, 0.0f);
splash.setImage(":/splash.svg");
splash.setPosition((Renderer::getScreenWidth() - splash.getSize().x()) / 2, (Renderer::getScreenHeight() - splash.getSize().y()) / 2 * 0.6f);
Expand Down
69 changes: 55 additions & 14 deletions es-core/src/components/ImageComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Renderer.h"
#include "ThemeData.h"
#include "Util.h"
#include "resources/SVGResource.h"
#include "Locale.h"

Eigen::Vector2i ImageComponent::getTextureSize() const
Expand All @@ -23,8 +22,9 @@ Eigen::Vector2f ImageComponent::getCenter() const
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
}

ImageComponent::ImageComponent(Window* window) : GuiComponent(window),
mTargetIsMax(false), mFlipX(false), mFlipY(false), mOrigin(0.0, 0.0), mTargetSize(0, 0), mColorShift(0xFFFFFFFF)
ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) : GuiComponent(window),
mTargetIsMax(false), mFlipX(false), mFlipY(false), mOrigin(0.0, 0.0), mTargetSize(0, 0), mColorShift(0xFFFFFFFF),
mForceLoad(forceLoad), mDynamic(dynamic), mFadeOpacity(0.0f), mFading(false)
{
updateColors();
}
Expand All @@ -38,9 +38,7 @@ void ImageComponent::resize()
if(!mTexture)
return;

SVGResource* svg = dynamic_cast<SVGResource*>(mTexture.get());

const Eigen::Vector2f textureSize = svg ? svg->getSourceImageSize() : Eigen::Vector2f((float)mTexture->getSize().x(), (float)mTexture->getSize().y());
const Eigen::Vector2f textureSize = mTexture->getSourceImageSize();
if(textureSize.isZero())
return;

Expand Down Expand Up @@ -91,12 +89,8 @@ void ImageComponent::resize()
}
}
}

if(svg)
{
// mSize.y() should already be rounded
svg->rasterizeAt((int)round(mSize.x()), (int)round(mSize.y()));
}
// mSize.y() should already be rounded
mTexture->rasterizeAt((int)round(mSize.x()), (int)round(mSize.y()));

onSizeChanged();
}
Expand All @@ -111,7 +105,7 @@ void ImageComponent::setImage(const std::string& path, bool tile)
if(path.empty() || !ResourceManager::getInstance()->fileExists(path))
mTexture.reset();
else
mTexture = TextureResource::get(path, tile);
mTexture = TextureResource::get(path, tile, mForceLoad, mDynamic);

resize();
}
Expand Down Expand Up @@ -167,6 +161,9 @@ void ImageComponent::setFlipY(bool flip)
void ImageComponent::setColorShift(unsigned int color)
{
mColorShift = color;
// Grab the opacity from the color shift because we may need to apply it if
// fading textures in
mOpacity = color & 0xff;
updateColors();
}

Expand Down Expand Up @@ -248,7 +245,10 @@ void ImageComponent::render(const Eigen::Affine3f& parentTrans)
if(mTexture->isInitialized())
{
// actually draw the image
mTexture->bind();
// The bind() function returns false if the texture is not currently loaded. A blank
// texture is bound in this case but we want to handle a fade so it doesn't just 'jump' in
// when it finally loads
fadeIn(mTexture->bind());

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
Expand Down Expand Up @@ -279,6 +279,47 @@ void ImageComponent::render(const Eigen::Affine3f& parentTrans)
GuiComponent::renderChildren(trans);
}

void ImageComponent::fadeIn(bool textureLoaded)
{
if (!mForceLoad)
{
if (!textureLoaded)
{
// Start the fade if this is the first time we've encountered the unloaded texture
if (!mFading)
{
// Start with a zero opacity and flag it as fading
mFadeOpacity = 0;
mFading = true;
// Set the colours to be translucent
mColorShift = (mColorShift >> 8 << 8) | 0;
updateColors();
}
}
else if (mFading)
{
// The texture is loaded and we need to fade it in. The fade is based on the frame rate
// and is 1/4 second if running at 60 frames per second although the actual value is not
// that important
int opacity = mFadeOpacity + 255 / 15;
// See if we've finished fading
if (opacity >= 255)
{
mFadeOpacity = 255;
mFading = false;
}
else
{
mFadeOpacity = (unsigned char)opacity;
}
// Apply the combination of the target opacity and current fade
float newOpacity = (float)mOpacity * ((float)mFadeOpacity / 255.0f);
mColorShift = (mColorShift >> 8 << 8) | (unsigned char)newOpacity;
updateColors();
}
}
}

bool ImageComponent::hasImage()
{
return (bool)mTexture;
Expand Down
7 changes: 6 additions & 1 deletion es-core/src/components/ImageComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ImageComponent : public GuiComponent
{
public:
ImageComponent(Window* window);
ImageComponent(Window* window, bool forceLoad = false, bool dynamic = true);
virtual ~ImageComponent();

//Loads the image at the given filepath. Will tile if tile is true (retrieves texture as tiling, creates vertices accordingly).
Expand Down Expand Up @@ -81,10 +81,15 @@ class ImageComponent : public GuiComponent

void updateVertices();
void updateColors();
void fadeIn(bool textureLoaded);

unsigned int mColorShift;

std::shared_ptr<TextureResource> mTexture;
unsigned char mFadeOpacity;
bool mFading;
bool mForceLoad;
bool mDynamic;
};

#endif
Loading