mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Fixed ParticleSystems and Files crashing instead of erroring when given bad sizes (issue #666)
This commit is contained in:
@@ -136,6 +136,9 @@ FileData *File::read(int64 size)
|
||||
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;
|
||||
|
||||
@@ -63,7 +63,7 @@ StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_M
|
||||
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)
|
||||
@@ -95,6 +95,9 @@ ParticleSystem::ParticleSystem(Image *image, unsigned int buffer)
|
||||
, 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);
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
/**
|
||||
* 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.
|
||||
@@ -503,7 +503,7 @@ public:
|
||||
protected:
|
||||
|
||||
// The max amount of particles.
|
||||
unsigned int bufferSize;
|
||||
int bufferSize;
|
||||
|
||||
// Pointer to the first particle.
|
||||
particle *pStart;
|
||||
|
||||
@@ -409,7 +409,15 @@ int w_newParticleSystem(lua_State *L)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user