Commits

Alex Szpakowski committed de016bd

Fixed ParticleSystems and Files crashing instead of erroring when given bad sizes (issue #666)

  • Participants
  • Parent commits baea529

Comments (0)

Files changed (4)

src/modules/filesystem/physfs/File.cpp

 	int64 cur = tell();
 	size = (size == ALL) ? max : size;
 
+	if (size < 0)
+		throw love::Exception("Invalid read size.");
+
 	// Clamping because the file offset may be in a weird position.
 	if (cur < 0)
 		cur = 0;

src/modules/graphics/opengl/ParticleSystem.cpp

 StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries));
 
 
-ParticleSystem::ParticleSystem(Image *image, unsigned int buffer)
+ParticleSystem::ParticleSystem(Image *image, int buffer)
 	: pStart(0)
 	, pLast(0)
 	, pEnd(0)
 	, offsetX(image->getWidth()*0.5f)
 	, offsetY(image->getHeight()*0.5f)
 {
+	if (buffer <= 0)
+		throw love::Exception("Invalid ParticleSystem size.");
+
 	sizes.push_back(1.0f);
 	colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
 	setBufferSize(buffer);

src/modules/graphics/opengl/ParticleSystem.h

 	/**
 	 * Creates a particle system with the specified buffersize and image.
 	 **/
-	ParticleSystem(Image *image, unsigned int buffer);
+	ParticleSystem(Image *image, int buffer);
 
 	/**
 	 * Deletes any allocated memory.
 protected:
 
 	// The max amount of particles.
-	unsigned int bufferSize;
+	int bufferSize;
 
 	// Pointer to the first particle.
 	particle *pStart;

src/modules/graphics/opengl/wrap_Graphics.cpp

 {
 	Image *image = luax_checkimage(L, 1);
 	int size = luaL_optint(L, 2, 1000);
-	ParticleSystem *t = instance->newParticleSystem(image, size);
+	ParticleSystem *t = 0;
+	try
+	{
+		t = instance->newParticleSystem(image, size);
+	}
+	catch (love::Exception &e)
+	{
+		return luaL_error(L, "%s", e.what());
+	}
 	luax_newtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, (void *)t);
 	return 1;
 }