Commits

Alex Szpakowski committed 1c61424

Cleaned up exception handling code when creating new fonts, spritebatches, and shaders

Comments (0)

Files changed (3)

src/modules/graphics/opengl/Font.cpp

 	, filter(filter)
 	, mipmapsharpness(0.0f)
 {
-	love::font::GlyphData *gd = r->getGlyphData(32);
-	type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
-	delete gd;
-
 	// try to find the best texture size match for the font size
 	// default to the largest texture size if no rough match is found
 	texture_size_index = NUM_TEXTURE_SIZES - 1;
 	texture_width = TEXTURE_WIDTHS[texture_size_index];
 	texture_height = TEXTURE_HEIGHTS[texture_size_index];
 
-	loadVolatile();
+	love::font::GlyphData *gd = 0;
 
-	r->retain();
+	try
+	{
+		gd = r->getGlyphData(32);
+		loadVolatile();
+	}
+	catch (love::Exception &)
+	{
+		delete gd;
+		throw;
+	}
+
+	type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA) ? FONT_TRUETYPE : FONT_IMAGE;
+	delete gd;
+
+	rasterizer->retain();
 }
 
 Font::~Font()

src/modules/graphics/opengl/Graphics.cpp

 
 Font *Graphics::newFont(love::font::Rasterizer *r, const Image::Filter &filter)
 {
-	Font *font = new Font(r, filter);
-
-	// Load it and check for errors.
-	if (!font)
-	{
-		delete font;
-		return 0;
-	}
-
-	return font;
+	return new Font(r, filter);
 }
 
 SpriteBatch *Graphics::newSpriteBatch(Image *image, int size, int usage)
 {
-	SpriteBatch *t = NULL;
-	try
-	{
-		t = new SpriteBatch(image, size, usage);
-	}
-	catch(love::Exception &e)
-	{
-		if (t) delete t;
-		throw e;
-	}
-	return t;
+	return new SpriteBatch(image, size, usage);
 }
 
 ParticleSystem *Graphics::newParticleSystem(Image *image, int size)
 
 Shader *Graphics::newShader(const Shader::ShaderSources &sources)
 {
-	Shader *shader = NULL;
-	try
-	{
-		shader = new Shader(sources);
-	}
-	catch(love::Exception &)
-	{
-		if (shader)
-			delete shader;
-		
-		throw;
-	}
-	return shader;
+	return new Shader(sources);
 }
 
 void Graphics::setColor(const Color &c)

src/modules/graphics/opengl/ParticleSystem.cpp

 	, pLast(0)
 	, pEnd(0)
 	, particleVerts(0)
+	, sprite(sprite)
 	, active(true)
 	, emissionRate(0)
 	, emitCounter(0)
 	, offsetX(sprite->getWidth()*0.5f)
 	, offsetY(sprite->getHeight()*0.5f)
 {
-	this->sprite = sprite;
-	sprite->retain();
 	sizes.push_back(1.0f);
 	colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
 	setBufferSize(buffer);
+	sprite->retain();
 }
 
 ParticleSystem::~ParticleSystem()