mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +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);
|
||||
radius = def->radius;
|
||||
this->localPosition = def->localPosition;
|
||||
|
||||
def->userData = (void*)data;
|
||||
shape = body->body->CreateShape(def);
|
||||
shape->SetUserData((void*)data);
|
||||
}
|
||||
|
||||
CircleShape::~CircleShape()
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint::DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2)
|
||||
: Joint(body1, body2)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x1,y1)), world->scaleDown(b2Vec2(x2,y2)));
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint::GearJoint(Joint * joint1, Joint * joint2, float ratio)
|
||||
: Joint(joint1->body2, joint2->body2)
|
||||
: Joint(joint1->body2, joint2->body2), joint(NULL)
|
||||
{
|
||||
b2GearJointDef def;
|
||||
def.joint1 = joint1->joint;
|
||||
|
||||
@@ -117,7 +117,8 @@ namespace box2d
|
||||
|
||||
void Joint::destroyJoint(b2Joint * joint)
|
||||
{
|
||||
world->world->DestroyJoint(joint);
|
||||
if (joint != NULL)
|
||||
world->world->DestroyJoint(joint);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint::MouseJoint(Body * body1, float x, float y)
|
||||
: Joint(body1)
|
||||
: Joint(body1), joint(NULL)
|
||||
{
|
||||
b2MouseJointDef def;
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace box2d
|
||||
for(int i = 0; i<def->vertexCount; i++)
|
||||
def->vertices[i] = body->world->scaleDown(def->vertices[i]);
|
||||
|
||||
def->userData = (void*)data;
|
||||
shape = body->body->CreateShape(def);
|
||||
shape->SetUserData((void*)data);
|
||||
}
|
||||
|
||||
PolygonShape::~PolygonShape()
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
|
||||
: Joint(body1, body2)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2PrismaticJointDef def;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
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;
|
||||
def.Initialize(body1->body, body2->body, world->scaleDown(groundAnchor1), world->scaleDown(groundAnchor2), \
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint::RevoluteJoint(Body * body1, Body * body2, float x, float y)
|
||||
: Joint(body1, body2)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x,y)));
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
Shape::Shape(Body * body)
|
||||
: body(body)
|
||||
: body(body), shape(NULL)
|
||||
{
|
||||
body->retain();
|
||||
data = new shapeudata();
|
||||
@@ -49,7 +49,8 @@ namespace box2d
|
||||
delete data;
|
||||
data = 0;
|
||||
|
||||
body->body->DestroyShape(shape);
|
||||
if (shape)
|
||||
body->body->DestroyShape(shape);
|
||||
shape = 0;
|
||||
|
||||
body->release();
|
||||
|
||||
@@ -96,14 +96,14 @@ namespace box2d
|
||||
}
|
||||
|
||||
World::World(b2AABB aabb)
|
||||
: meter(DEFAULT_METER)
|
||||
: meter(DEFAULT_METER), world(NULL)
|
||||
{
|
||||
world = new b2World(scaleDown(aabb), b2Vec2(0,0), true);
|
||||
world->SetContactListener(this);
|
||||
}
|
||||
|
||||
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->SetContactListener(this);
|
||||
|
||||
Reference in New Issue
Block a user