diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-01-12 06:14:15 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-01-12 06:14:15 -0300 |
commit | a625f7d07317ac4fac21962a99a7896ed13010c7 (patch) | |
tree | ffd18fbbd0507555e8c9966947e5c6a4bb1db1ad /scene/3d | |
parent | eab1e5b5967ccebf00ce1d456eb1fd6ee28ec96d (diff) |
-Properly lock and and warn about switching off contact monitoring, fixes #3041
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/physics_body.cpp | 24 | ||||
-rw-r--r-- | scene/3d/physics_body.h | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index de777604b0..1a2665b6ad 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -207,6 +207,9 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { ERR_FAIL_COND(E->get().in_tree); E->get().in_tree=true; + + contact_monitor->locked=true; + emit_signal(SceneStringNames::get_singleton()->body_enter,node); for(int i=0;i<E->get().shapes.size();i++) { @@ -214,6 +217,9 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { emit_signal(SceneStringNames::get_singleton()->body_enter_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + contact_monitor->locked=false; + + } void RigidBody::_body_exit_tree(ObjectID p_id) { @@ -225,11 +231,18 @@ void RigidBody::_body_exit_tree(ObjectID p_id) { ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->get().in_tree); E->get().in_tree=false; + + contact_monitor->locked=true; + emit_signal(SceneStringNames::get_singleton()->body_exit,node); + for(int i=0;i<E->get().shapes.size();i++) { emit_signal(SceneStringNames::get_singleton()->body_exit_shape,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape); } + + contact_monitor->locked=false; + } void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape) { @@ -317,6 +330,8 @@ void RigidBody::_direct_state_changed(Object *p_state) { if (contact_monitor) { + contact_monitor->locked=true; + //untag all int rc=0; for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { @@ -396,6 +411,8 @@ void RigidBody::_direct_state_changed(Object *p_state) { _body_inout(1,toadd[i].id,toadd[i].shape,toadd[i].local_shape); } + contact_monitor->locked=false; + } set_ignore_transform_notification(true); @@ -648,6 +665,11 @@ void RigidBody::set_contact_monitor(bool p_enabled) { if (!p_enabled) { + if (contact_monitor->locked) { + ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead"); + } + ERR_FAIL_COND(contact_monitor->locked); + for(Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { //clean up mess @@ -658,6 +680,8 @@ void RigidBody::set_contact_monitor(bool p_enabled) { } else { contact_monitor = memnew( ContactMonitor ); + contact_monitor->locked=false; + } } diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 0d6c358e28..da79d63f00 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -175,7 +175,7 @@ private: struct ContactMonitor { - + bool locked; Map<ObjectID,BodyState> body_map; }; |