Fixed console spam when an ImageComponent has an invalid texture.

This commit is contained in:
Aloshi 2014-03-24 16:29:56 -05:00
parent 7875c2271c
commit 0464776e62
6 changed files with 41 additions and 28 deletions

View file

@ -63,12 +63,12 @@ void HelpComponent::updateGrid()
std::vector< std::shared_ptr<TextComponent> > labels; std::vector< std::shared_ptr<TextComponent> > labels;
float width = 0; float width = 0;
const float height = font->getHeight(); const float height = font->getLetterHeight();
for(auto it = mPrompts.begin(); it != mPrompts.end(); it++) for(auto it = mPrompts.begin(); it != mPrompts.end(); it++)
{ {
auto icon = std::make_shared<ImageComponent>(mWindow); auto icon = std::make_shared<ImageComponent>(mWindow);
icon->setImage(getIconTexture(it->first)); icon->setImage(getIconTexture(it->first));
icon->setResize(0, height * 0.8f); icon->setResize(0, height);
icons.push_back(icon); icons.push_back(icon);
auto lbl = std::make_shared<TextComponent>(mWindow, strToUpper(it->second), font, 0x777777FF); auto lbl = std::make_shared<TextComponent>(mWindow, strToUpper(it->second), font, 0x777777FF);

View file

@ -149,22 +149,28 @@ void ImageComponent::render(const Eigen::Affine3f& parentTrans)
if(mTexture && getOpacity() > 0) if(mTexture && getOpacity() > 0)
{ {
GLfloat points[12], texs[12]; if(mTexture->isInitialized())
GLubyte colors[6*4];
if(mTexture->isTiled())
{ {
float xCount = mSize.x() / getTextureSize().x(); GLfloat points[12], texs[12];
float yCount = mSize.y() / getTextureSize().y(); GLubyte colors[6*4];
Renderer::buildGLColorArray(colors, (mColorShift >> 8 << 8)| (getOpacity()), 6);
buildImageArray(0, 0, points, texs, xCount, yCount);
}else{
Renderer::buildGLColorArray(colors, (mColorShift >> 8 << 8) | (getOpacity()), 6);
buildImageArray(0, 0, points, texs);
}
drawImageArray(points, texs, colors, 6); if(mTexture->isTiled())
{
float xCount = mSize.x() / getTextureSize().x();
float yCount = mSize.y() / getTextureSize().y();
Renderer::buildGLColorArray(colors, (mColorShift >> 8 << 8)| (getOpacity()), 6);
buildImageArray(0, 0, points, texs, xCount, yCount);
}else{
Renderer::buildGLColorArray(colors, (mColorShift >> 8 << 8) | (getOpacity()), 6);
buildImageArray(0, 0, points, texs);
}
drawImageArray(points, texs, colors, 6);
}else{
LOG(LogError) << "Image texture is not initialized!";
mTexture.reset();
}
} }
GuiComponent::renderChildren(trans); GuiComponent::renderChildren(trans);

View file

@ -233,25 +233,26 @@ void ScraperSearchComponent::updateInfoPane()
int i = getSelectedIndex(); int i = getSelectedIndex();
if(i != -1 && (int)mScraperResults.size() > i) if(i != -1 && (int)mScraperResults.size() > i)
{ {
mResultName->setText(mScraperResults.at(i).mdl.get("name")); ScraperSearchResult& res = mScraperResults.at(i);
mResultDesc->setText(mScraperResults.at(i).mdl.get("desc")); mResultName->setText(res.mdl.get("name"));
mResultDesc->setText(res.mdl.get("desc"));
mDescContainer->setScrollPos(Eigen::Vector2d(0, 0)); mDescContainer->setScrollPos(Eigen::Vector2d(0, 0));
mDescContainer->resetAutoScrollTimer(); mDescContainer->resetAutoScrollTimer();
mResultThumbnail->setImage(""); mResultThumbnail->setImage("");
const std::string& thumb = mScraperResults.at(i).thumbnailUrl; const std::string& thumb = res.thumbnailUrl.empty() ? res.imageUrl : res.thumbnailUrl;
if(!thumb.empty()) if(!thumb.empty())
mThumbnailReq = std::unique_ptr<HttpReq>(new HttpReq(thumb)); mThumbnailReq = std::unique_ptr<HttpReq>(new HttpReq(thumb));
else else
mThumbnailReq.reset(); mThumbnailReq.reset();
// metadata // metadata
mMD_Rating->setValue(strToUpper(mScraperResults.at(i).mdl.get("rating"))); mMD_Rating->setValue(strToUpper(res.mdl.get("rating")));
mMD_ReleaseDate->setValue(strToUpper(mScraperResults.at(i).mdl.get("releasedate"))); mMD_ReleaseDate->setValue(strToUpper(res.mdl.get("releasedate")));
mMD_Developer->setText(strToUpper(mScraperResults.at(i).mdl.get("developer"))); mMD_Developer->setText(strToUpper(res.mdl.get("developer")));
mMD_Publisher->setText(strToUpper(mScraperResults.at(i).mdl.get("publisher"))); mMD_Publisher->setText(strToUpper(res.mdl.get("publisher")));
mMD_Genre->setText(strToUpper(mScraperResults.at(i).mdl.get("genre"))); mMD_Genre->setText(strToUpper(res.mdl.get("genre")));
mMD_Players->setText(strToUpper(mScraperResults.at(i).mdl.get("players"))); mMD_Players->setText(strToUpper(res.mdl.get("players")));
}else{ }else{
mResultName->setText(""); mResultName->setText("");

View file

@ -47,9 +47,9 @@ GuiDetectDevice::GuiDetectDevice(Window* window, bool firstRun) : GuiComponent(w
mGrid.setEntry(mDeviceInfo, Vector2i(0, 1), false, true); mGrid.setEntry(mDeviceInfo, Vector2i(0, 1), false, true);
// message // message
mMsg1 = std::make_shared<TextComponent>(mWindow, "HOLD A BUTTON ON YOUR DEVICE TO CONFIGURE IT", Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER); mMsg1 = std::make_shared<TextComponent>(mWindow, "HOLD A BUTTON ON YOUR DEVICE TO CONFIGURE IT.", Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER);
mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true); mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true);
mMsg2 = std::make_shared<TextComponent>(mWindow, "PRESS F4 TO QUIT AT ANY TIME", Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER); mMsg2 = std::make_shared<TextComponent>(mWindow, "PRESS F4 TO QUIT AT ANY TIME.", Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER);
mGrid.setEntry(mMsg2, Vector2i(0, 3), false, true); mGrid.setEntry(mMsg2, Vector2i(0, 3), false, true);
// currently held device // currently held device

View file

@ -62,7 +62,7 @@ void TextureResource::initFromMemory(const char* data, size_t length)
if(imageRGBA.size() == 0) if(imageRGBA.size() == 0)
{ {
LOG(LogError) << "Could not initialize texture from memory, invalid data! (" << mPath << ")"; LOG(LogError) << "Could not initialize texture from memory, invalid data! (file path: " << mPath << ", data ptr: " << (size_t)data << ", reported size: " << length << ")";
return; return;
} }
@ -137,3 +137,8 @@ std::shared_ptr<TextureResource> TextureResource::get(const std::string& path, b
tex->reload(ResourceManager::getInstance()); tex->reload(ResourceManager::getInstance());
return tex; return tex;
} }
bool TextureResource::isInitialized() const
{
return mTextureID != 0;
}

View file

@ -19,6 +19,7 @@ public:
virtual void unload(std::shared_ptr<ResourceManager>& rm) override; virtual void unload(std::shared_ptr<ResourceManager>& rm) override;
virtual void reload(std::shared_ptr<ResourceManager>& rm) override; virtual void reload(std::shared_ptr<ResourceManager>& rm) override;
bool isInitialized() const;
bool isTiled() const; bool isTiled() const;
const Eigen::Vector2i& getSize() const; const Eigen::Vector2i& getSize() const;
void bind() const; void bind() const;