mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Add NULL initializers for pointers.
Constructing invalid shapes, e.g. a rectangle with width 0, could result in a b2Assert to fail. In turn, Shape::~Shape tried to destroy a the shape with an uninitialized pointer, yielding a segfault. Add NULL-initializers and checks for NULL to prevent this.
This commit is contained in:
@@ -37,8 +37,9 @@ namespace box2d
|
|||||||
def->radius = body->world->scaleDown(def->radius);
|
def->radius = body->world->scaleDown(def->radius);
|
||||||
radius = def->radius;
|
radius = def->radius;
|
||||||
this->localPosition = def->localPosition;
|
this->localPosition = def->localPosition;
|
||||||
|
|
||||||
|
def->userData = (void*)data;
|
||||||
shape = body->body->CreateShape(def);
|
shape = body->body->CreateShape(def);
|
||||||
shape->SetUserData((void*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CircleShape::~CircleShape()
|
CircleShape::~CircleShape()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
DistanceJoint::DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2)
|
DistanceJoint::DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2)
|
||||||
: Joint(body1, body2)
|
: Joint(body1, body2), joint(NULL)
|
||||||
{
|
{
|
||||||
b2DistanceJointDef def;
|
b2DistanceJointDef def;
|
||||||
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x1,y1)), world->scaleDown(b2Vec2(x2,y2)));
|
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x1,y1)), world->scaleDown(b2Vec2(x2,y2)));
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
GearJoint::GearJoint(Joint * joint1, Joint * joint2, float ratio)
|
GearJoint::GearJoint(Joint * joint1, Joint * joint2, float ratio)
|
||||||
: Joint(joint1->body2, joint2->body2)
|
: Joint(joint1->body2, joint2->body2), joint(NULL)
|
||||||
{
|
{
|
||||||
b2GearJointDef def;
|
b2GearJointDef def;
|
||||||
def.joint1 = joint1->joint;
|
def.joint1 = joint1->joint;
|
||||||
|
|||||||
@@ -117,7 +117,8 @@ namespace box2d
|
|||||||
|
|
||||||
void Joint::destroyJoint(b2Joint * joint)
|
void Joint::destroyJoint(b2Joint * joint)
|
||||||
{
|
{
|
||||||
world->world->DestroyJoint(joint);
|
if (joint != NULL)
|
||||||
|
world->world->DestroyJoint(joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
MouseJoint::MouseJoint(Body * body1, float x, float y)
|
MouseJoint::MouseJoint(Body * body1, float x, float y)
|
||||||
: Joint(body1)
|
: Joint(body1), joint(NULL)
|
||||||
{
|
{
|
||||||
b2MouseJointDef def;
|
b2MouseJointDef def;
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace box2d
|
|||||||
for(int i = 0; i<def->vertexCount; i++)
|
for(int i = 0; i<def->vertexCount; i++)
|
||||||
def->vertices[i] = body->world->scaleDown(def->vertices[i]);
|
def->vertices[i] = body->world->scaleDown(def->vertices[i]);
|
||||||
|
|
||||||
|
def->userData = (void*)data;
|
||||||
shape = body->body->CreateShape(def);
|
shape = body->body->CreateShape(def);
|
||||||
shape->SetUserData((void*)data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PolygonShape::~PolygonShape()
|
PolygonShape::~PolygonShape()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
|
PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
|
||||||
: Joint(body1, body2)
|
: Joint(body1, body2), joint(NULL)
|
||||||
{
|
{
|
||||||
b2PrismaticJointDef def;
|
b2PrismaticJointDef def;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
PulleyJoint::PulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio)
|
PulleyJoint::PulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio)
|
||||||
: Joint(body1, body2)
|
: Joint(body1, body2), joint(NULL)
|
||||||
{
|
{
|
||||||
b2PulleyJointDef def;
|
b2PulleyJointDef def;
|
||||||
def.Initialize(body1->body, body2->body, world->scaleDown(groundAnchor1), world->scaleDown(groundAnchor2), \
|
def.Initialize(body1->body, body2->body, world->scaleDown(groundAnchor1), world->scaleDown(groundAnchor2), \
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
RevoluteJoint::RevoluteJoint(Body * body1, Body * body2, float x, float y)
|
RevoluteJoint::RevoluteJoint(Body * body1, Body * body2, float x, float y)
|
||||||
: Joint(body1, body2)
|
: Joint(body1, body2), joint(NULL)
|
||||||
{
|
{
|
||||||
b2RevoluteJointDef def;
|
b2RevoluteJointDef def;
|
||||||
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x,y)));
|
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x,y)));
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace physics
|
|||||||
namespace box2d
|
namespace box2d
|
||||||
{
|
{
|
||||||
Shape::Shape(Body * body)
|
Shape::Shape(Body * body)
|
||||||
: body(body)
|
: body(body), shape(NULL)
|
||||||
{
|
{
|
||||||
body->retain();
|
body->retain();
|
||||||
data = new shapeudata();
|
data = new shapeudata();
|
||||||
@@ -49,7 +49,8 @@ namespace box2d
|
|||||||
delete data;
|
delete data;
|
||||||
data = 0;
|
data = 0;
|
||||||
|
|
||||||
body->body->DestroyShape(shape);
|
if (shape)
|
||||||
|
body->body->DestroyShape(shape);
|
||||||
shape = 0;
|
shape = 0;
|
||||||
|
|
||||||
body->release();
|
body->release();
|
||||||
|
|||||||
@@ -96,14 +96,14 @@ namespace box2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
World::World(b2AABB aabb)
|
World::World(b2AABB aabb)
|
||||||
: meter(DEFAULT_METER)
|
: meter(DEFAULT_METER), world(NULL)
|
||||||
{
|
{
|
||||||
world = new b2World(scaleDown(aabb), b2Vec2(0,0), true);
|
world = new b2World(scaleDown(aabb), b2Vec2(0,0), true);
|
||||||
world->SetContactListener(this);
|
world->SetContactListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
World::World(b2AABB aabb, b2Vec2 gravity, bool sleep, int meter)
|
World::World(b2AABB aabb, b2Vec2 gravity, bool sleep, int meter)
|
||||||
: meter(meter)
|
: meter(meter), world(NULL)
|
||||||
{
|
{
|
||||||
world = new b2World(scaleDown(aabb), scaleDown(gravity), sleep);
|
world = new b2World(scaleDown(aabb), scaleDown(gravity), sleep);
|
||||||
world->SetContactListener(this);
|
world->SetContactListener(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user