Skip to content

Commit b301514

Browse files
authored
Merge pull request #53380 from timothyqiu/soft-body-3.x
2 parents 2b642d6 + ed5a98c commit b301514

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

modules/bullet/soft_body_bullet.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,24 @@ void SoftBodyBullet::get_node_offset(int p_node_index, btVector3 &r_offset) cons
201201
G_TO_B(off, r_offset);
202202
}
203203

204-
void SoftBodyBullet::set_node_mass(int node_index, btScalar p_mass) {
204+
void SoftBodyBullet::set_node_mass(int p_node_index, btScalar p_mass) {
205205
if (0 >= p_mass) {
206-
pin_node(node_index);
206+
pin_node(p_node_index);
207207
} else {
208-
unpin_node(node_index);
208+
unpin_node(p_node_index);
209209
}
210210
if (bt_soft_body) {
211-
bt_soft_body->setMass(node_index, p_mass);
211+
ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
212+
bt_soft_body->setMass(p_node_index, p_mass);
212213
}
213214
}
214215

215-
btScalar SoftBodyBullet::get_node_mass(int node_index) const {
216+
btScalar SoftBodyBullet::get_node_mass(int p_node_index) const {
216217
if (bt_soft_body) {
217-
return bt_soft_body->getMass(node_index);
218+
ERR_FAIL_INDEX_V(p_node_index, bt_soft_body->m_nodes.size(), 1);
219+
return bt_soft_body->getMass(p_node_index);
218220
} else {
219-
return -1 == search_node_pinned(node_index) ? 1 : 0;
221+
return -1 == search_node_pinned(p_node_index) ? 1 : 0;
220222
}
221223
}
222224

@@ -455,17 +457,25 @@ void SoftBodyBullet::setup_soft_body() {
455457

456458
// Set pinned nodes
457459
for (int i = pinned_nodes.size() - 1; 0 <= i; --i) {
458-
bt_soft_body->setMass(pinned_nodes[i], 0);
460+
const int node_index = pinned_nodes[i];
461+
ERR_CONTINUE(0 > node_index || bt_soft_body->m_nodes.size() <= node_index);
462+
bt_soft_body->setMass(node_index, 0);
459463
}
460464
}
461465

462466
void SoftBodyBullet::pin_node(int p_node_index) {
467+
if (bt_soft_body) {
468+
ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
469+
}
463470
if (-1 == search_node_pinned(p_node_index)) {
464471
pinned_nodes.push_back(p_node_index);
465472
}
466473
}
467474

468475
void SoftBodyBullet::unpin_node(int p_node_index) {
476+
if (bt_soft_body) {
477+
ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
478+
}
469479
const int id = search_node_pinned(p_node_index);
470480
if (-1 != id) {
471481
pinned_nodes.remove(id);

0 commit comments

Comments
 (0)