diff options
author | Leandro Dorileo <dorileo@profusion.mobi> | 2012-11-29 18:54:36 +0000 |
---|---|---|
committer | Leandro Dorileo <dorileo@profusion.mobi> | 2012-11-29 18:54:36 +0000 |
commit | 40e3df112103ded17b2249ccf01e588c713a14bf (patch) | |
tree | 985d4ab9469ab460f3aabad63fb17af1f5afe2fd /legacy/ephysics/src/lib | |
parent | 9e76f59766a386613dec6512cc7a2469f1a5dc41 (diff) | |
download | efl-40e3df112103ded17b2249ccf01e588c713a14bf.tar.gz efl-40e3df112103ded17b2249ccf01e588c713a14bf.tar.xz efl-40e3df112103ded17b2249ccf01e588c713a14bf.zip |
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
Diffstat (limited to 'legacy/ephysics/src/lib')
-rw-r--r-- | legacy/ephysics/src/lib/ephysics_body.cpp | 2 | ||||
-rw-r--r-- | legacy/ephysics/src/lib/ephysics_constraints.cpp | 36 | ||||
-rw-r--r-- | legacy/ephysics/src/lib/ephysics_private.h | 2 | ||||
-rw-r--r-- | legacy/ephysics/src/lib/ephysics_world.cpp | 6 |
4 files changed, 41 insertions, 5 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 1a92b2e29..12dd0209b 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -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); diff --git a/legacy/ephysics/src/lib/ephysics_constraints.cpp b/legacy/ephysics/src/lib/ephysics_constraints.cpp index f97af5865..5e36fcbf3 100644 --- a/legacy/ephysics/src/lib/ephysics_constraints.cpp +++ b/legacy/ephysics/src/lib/ephysics_constraints.cpp @@ -15,6 +15,36 @@ struct _EPhysics_Constraint { }; 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) { btVector3 linear_limit; @@ -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); } diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 818ec706b..8afeee7b5 100644 --- a/legacy/ephysics/src/lib/ephysics_private.h +++ b/legacy/ephysics/src/lib/ephysics_private.h @@ -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); diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp index f1004bb3c..2aef76529 100644 --- a/legacy/ephysics/src/lib/ephysics_world.cpp +++ b/legacy/ephysics/src/lib/ephysics_world.cpp @@ -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) { |