Skip to content

Commit

Permalink
PackedTexture: Handle texture creation failure
Browse files Browse the repository at this point in the history
Prevents possible crashes later on.

See: crash report #444
  • Loading branch information
dscharrer committed Jan 26, 2013
1 parent 3eec2ef commit 818a67e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/graphics/d3d9/D3D9Texture2D.cpp
Expand Up @@ -58,8 +58,8 @@ DX9Texture2D::~DX9Texture2D()
Destroy();
}

bool DX9Texture2D::Create()
{
bool DX9Texture2D::Create() {

arx_assert_msg(m_pTexture == 0, "Texture already created!");
arx_assert(size.x != 0);
arx_assert(size.y != 0);
Expand Down
9 changes: 8 additions & 1 deletion src/graphics/font/Font.cpp
Expand Up @@ -159,7 +159,14 @@ bool Font::insertGlyph(Char character) {
memcpy(dst, src, glyph.size.x * glyph.size.y);

Vec2i offset;
textures->insertImage(imgGlyph, glyph.texture, offset);
if(!textures->insertImage(imgGlyph, glyph.texture, offset)) {
std::ostringstream oss;
util::writeUTF8(std::ostream_iterator<char>(oss), character);
LogWarning << "Could not upload glyph for character U+" << std::hex << character
<< " (" << oss.str() << ") in font " << info.name;
insertPlaceholderGlyph(character);
return false;
}

// Compute UV mapping for each glyph.
const float textureSize = textures->getTextureSize();
Expand Down
15 changes: 13 additions & 2 deletions src/graphics/texture/PackedTexture.cpp
Expand Up @@ -21,6 +21,7 @@

#include "graphics/Renderer.h"
#include "graphics/texture/Texture.h"
#include "io/log/Logger.h"

PackedTexture::PackedTexture(unsigned int pSize, Image::Format pFormat)
: textureSize(pSize), textureFormat(pFormat) { }
Expand Down Expand Up @@ -49,7 +50,12 @@ PackedTexture::TextureTree::TextureTree(unsigned int textureSize,
root.rect = Rect(0, 0, textureSize - 1, textureSize - 1);

texture = GRenderer->CreateTexture2D();
texture->Init(textureSize, textureSize, textureFormat);
if(!texture->Init(textureSize, textureSize, textureFormat)) {
LogError << "Could not create texture for size " << textureSize
<< " and format " << textureFormat;
delete texture, texture = NULL;
return;
}
texture->GetImage().Clear();
dirty = true;
}
Expand Down Expand Up @@ -89,7 +95,12 @@ bool PackedTexture::insertImage(const Image & image, unsigned int & textureIndex

// No space found, create a new texture
if(!node) {
textures.push_back(new TextureTree(textureSize, textureFormat));
TextureTree * newTree = new TextureTree(textureSize, textureFormat);
if(!newTree->texture) {
delete newTree;
return false;
}
textures.push_back(newTree);
node = textures[textures.size() - 1]->insertImage(image);
nodeTree = textures.size() - 1;
}
Expand Down

0 comments on commit 818a67e

Please sign in to comment.