diff options
| author | Pedro J. Estébanez | 2017-07-25 04:26:47 +0200 |
|---|---|---|
| committer | Pedro J. Estébanez | 2017-08-01 01:39:40 +0200 |
| commit | 7264716e8666b3a5d80f96f645226235e55c7b6f (patch) | |
| tree | fd4c2b0bb3233230ee1f4859c9c2618d15eb8dd4 /servers/physics_2d/physics_2d_server_sw.cpp | |
| parent | ac2c5e8dcdf4c4957fc20b124b91847c6b0145ad (diff) | |
| download | godot-7264716e8666b3a5d80f96f645226235e55c7b6f.tar.gz godot-7264716e8666b3a5d80f96f645226235e55c7b6f.tar.zst godot-7264716e8666b3a5d80f96f645226235e55c7b6f.zip | |
Improve cleanup of physics constraints
Don't abort the loop when one is already released
Remove warning on already-released constraint
Clean up area's contraints as well
Clear the constraint data as well
Do the cleanup as soon as the space changes
Diffstat (limited to '')
| -rw-r--r-- | servers/physics_2d/physics_2d_server_sw.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 98fe7da3e..add376bfb 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -296,6 +296,14 @@ void Physics2DServerSW::area_set_space(RID p_area, RID p_space) { if (area->get_space() == space) return; //pointless + for (Set<Constraint2DSW *>::Element *E = area->get_constraints().front(); E; E = E->next()) { + RID self = E->get()->get_self(); + if (!self.is_valid()) + continue; + free(self); + } + area->clear_constraints(); + area->set_space(space); }; @@ -540,6 +548,14 @@ void Physics2DServerSW::body_set_space(RID p_body, RID p_space) { if (body->get_space() == space) return; //pointless + while (body->get_constraint_map().size()) { + RID self = body->get_constraint_map().front()->key()->get_self(); + if (!self.is_valid()) + continue; + free(self); + } + body->clear_constraint_map(); + body->set_space(space); }; @@ -1080,19 +1096,13 @@ void Physics2DServerSW::free(RID p_rid) { _clear_query(body->get_direct_state_query()); */ - body->set_space(NULL); + body_set_space(p_rid, RID()); while (body->get_shape_count()) { body->remove_shape(0); } - while (body->get_constraint_map().size()) { - RID self = body->get_constraint_map().front()->key()->get_self(); - ERR_FAIL_COND(!self.is_valid()); - free(self); - } - body_owner.free(p_rid); memdelete(body); |
