diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 1a92b2e293..12dd0209bb 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 f97af58659..5e36fcbf36 100644 --- a/legacy/ephysics/src/lib/ephysics_constraints.cpp +++ b/legacy/ephysics/src/lib/ephysics_constraints.cpp @@ -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); } diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 818ec706b1..8afeee7b5d 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 f1004bb3c8..2aef765293 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) {