summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:54:36 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-11-29 18:54:36 +0000
commit40e3df112103ded17b2249ccf01e588c713a14bf (patch)
tree985d4ab9469ab460f3aabad63fb17af1f5afe2fd /legacy/ephysics
parent9e76f59766a386613dec6512cc7a2469f1a5dc41 (diff)
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')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp2
-rw-r--r--legacy/ephysics/src/lib/ephysics_constraints.cpp36
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h2
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp6
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 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)
1218 free(cb); 1218 free(cb);
1219 } 1219 }
1220 1220
1221 ephysics_constraint_body_del(body);
1222
1221 EINA_LIST_FREE(body->collision_groups, group) 1223 EINA_LIST_FREE(body->collision_groups, group)
1222 eina_stringshare_del((Eina_Stringshare *)group); 1224 eina_stringshare_del((Eina_Stringshare *)group);
1223 1225
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
@@ -15,6 +15,36 @@ struct _EPhysics_Constraint {
15}; 15};
16 16
17static void 17static void
18_ephysics_constraint_del(EPhysics_Constraint *constraint)
19{
20 ephysics_world_constraint_del(constraint->world, constraint,
21 constraint->bt_constraint);
22 delete constraint->bt_constraint;
23 free(constraint);
24}
25
26void
27ephysics_constraint_body_del(EPhysics_Body *body)
28{
29 void *ldata;
30 EPhysics_Constraint *constraint;
31 Eina_List *l, *constraints, *rem = NULL;
32
33 constraints = ephysics_world_constraints_get(body->world);
34 if (!constraints) return;
35
36 EINA_LIST_FOREACH(constraints, l, ldata)
37 {
38 constraint = (EPhysics_Constraint *)ldata;
39 if (constraint->bodies[0] == body || constraint->bodies[1])
40 rem = eina_list_append(rem, constraint);
41 }
42
43 EINA_LIST_FREE(rem, ldata)
44 _ephysics_constraint_del((EPhysics_Constraint *)ldata);
45}
46
47static void
18_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) 48_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)
19{ 49{
20 btVector3 linear_limit; 50 btVector3 linear_limit;
@@ -374,11 +404,7 @@ ephysics_constraint_del(EPhysics_Constraint *constraint)
374 } 404 }
375 405
376 ephysics_world_lock_take(constraint->world); 406 ephysics_world_lock_take(constraint->world);
377 ephysics_world_constraint_del(constraint->world, constraint, 407 _ephysics_constraint_del(constraint);
378 constraint->bt_constraint);
379 delete constraint->bt_constraint;
380 free(constraint);
381
382 INF("Constraint deleted."); 408 INF("Constraint deleted.");
383 ephysics_world_lock_release(constraint->world); 409 ephysics_world_lock_release(constraint->world);
384} 410}
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)
184btSoftBodyWorldInfo *ephysics_world_info_get(const EPhysics_World *world); 184btSoftBodyWorldInfo *ephysics_world_info_get(const EPhysics_World *world);
185void ephysics_world_lock_take(EPhysics_World *world); 185void ephysics_world_lock_take(EPhysics_World *world);
186void ephysics_world_lock_release(EPhysics_World *world); 186void ephysics_world_lock_release(EPhysics_World *world);
187Eina_List *ephysics_world_constraints_get(EPhysics_World *world);
187 188
188/* Body */ 189/* Body */
189Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1); 190Eina_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);
199void ephysics_body_evas_objects_restack(EPhysics_World *world); 200void ephysics_body_evas_objects_restack(EPhysics_World *world);
200void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body); 201void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body);
201void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body); 202void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body);
203void ephysics_constraint_body_del(EPhysics_Body *body);
202 204
203/* Camera */ 205/* Camera */
204EPhysics_Camera *ephysics_camera_add(EPhysics_World *world); 206EPhysics_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)
499 return EINA_TRUE; 499 return EINA_TRUE;
500} 500}
501 501
502Eina_List *
503ephysics_world_constraints_get(EPhysics_World *world)
504{
505 return world->constraints;
506}
507
502void 508void
503ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint) 509ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint)
504{ 510{