EPhysics: constraint removal

Delete the constraints a body belongs to on body removal and avoid
bullet to segfault.

--This line, and those below, will be ignored--


SVN revision: 79850
This commit is contained in:
Leandro Dorileo 2012-11-29 18:54:36 +00:00
parent 9e76f59766
commit 40e3df1121
4 changed files with 41 additions and 5 deletions

View File

@ -1218,6 +1218,8 @@ _ephysics_body_del(EPhysics_Body *body)
free(cb);
}
ephysics_constraint_body_del(body);
EINA_LIST_FREE(body->collision_groups, group)
eina_stringshare_del((Eina_Stringshare *)group);

View File

@ -14,6 +14,36 @@ struct _EPhysics_Constraint {
EPhysics_Body *bodies[2];
};
static void
_ephysics_constraint_del(EPhysics_Constraint *constraint)
{
ephysics_world_constraint_del(constraint->world, constraint,
constraint->bt_constraint);
delete constraint->bt_constraint;
free(constraint);
}
void
ephysics_constraint_body_del(EPhysics_Body *body)
{
void *ldata;
EPhysics_Constraint *constraint;
Eina_List *l, *constraints, *rem = NULL;
constraints = ephysics_world_constraints_get(body->world);
if (!constraints) return;
EINA_LIST_FOREACH(constraints, l, ldata)
{
constraint = (EPhysics_Constraint *)ldata;
if (constraint->bodies[0] == body || constraint->bodies[1])
rem = eina_list_append(rem, constraint);
}
EINA_LIST_FREE(rem, ldata)
_ephysics_constraint_del((EPhysics_Constraint *)ldata);
}
static void
_ephysics_constraint_linear_limit_get(const EPhysics_Constraint *constraint, Evas_Coord *lower_x, Evas_Coord *upper_x, Evas_Coord *lower_y, Evas_Coord *upper_y, Evas_Coord *lower_z, Evas_Coord *upper_z, double rate)
{
@ -374,11 +404,7 @@ ephysics_constraint_del(EPhysics_Constraint *constraint)
}
ephysics_world_lock_take(constraint->world);
ephysics_world_constraint_del(constraint->world, constraint,
constraint->bt_constraint);
delete constraint->bt_constraint;
free(constraint);
_ephysics_constraint_del(constraint);
INF("Constraint deleted.");
ephysics_world_lock_release(constraint->world);
}

View File

@ -184,6 +184,7 @@ Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world)
btSoftBodyWorldInfo *ephysics_world_info_get(const EPhysics_World *world);
void ephysics_world_lock_take(EPhysics_World *world);
void ephysics_world_lock_release(EPhysics_World *world);
Eina_List *ephysics_world_constraints_get(EPhysics_World *world);
/* Body */
Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1);
@ -199,6 +200,7 @@ void ephysics_body_activate(const EPhysics_Body *body, Eina_Bool activate);
void ephysics_body_evas_objects_restack(EPhysics_World *world);
void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body);
void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body);
void ephysics_constraint_body_del(EPhysics_Body *body);
/* Camera */
EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);

View File

@ -499,6 +499,12 @@ ephysics_world_soft_body_add(EPhysics_World *world, EPhysics_Body *body)
return EINA_TRUE;
}
Eina_List *
ephysics_world_constraints_get(EPhysics_World *world)
{
return world->constraints;
}
void
ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint)
{