Skip to content

Commit

Permalink
Fix crash during PROTO regeneration due to invalid search of parent f…
Browse files Browse the repository at this point in the history
…ield (cyberbotics#5724)

* Fix crash during regeneration due to invalid search of parent field

* Add entry in ChangeLog
  • Loading branch information
stefaniapedrazzi authored Feb 7, 2023
1 parent 5441547 commit 6af2bcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2023.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Released on ??
- Fixed performance issues when retrieving multiple times a node's field defined in a PROTO body using the [Supervisor API](supervisor.md) ([#5774](https://github.com/cyberbotics/webots/pull/5774)).
- Fixed failure to detect that a port was already in use on some platforms ([#5806](https://github.com/cyberbotics/webots/pull/5806)).
- Fixed thread-safety issue when robots collide. This was only an issue if physics multi-threading was enabled (which is not the default and rarely used) ([#5796](https://github.com/cyberbotics/webots/pull/5796)).
- Fixed crash during PROTO regeneration triggered by nested PROTO in parameter ([#5724](https://github.com/cyberbotics/webots/pull/5724)).

## Webots R2023a
Released on November 29th, 2022.
Expand Down
13 changes: 10 additions & 3 deletions src/webots/nodes/utils/WbTemplateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ bool WbTemplateManager::nodeNeedsToSubscribe(WbNode *node) {
if (!node->isProtoInstance())
return false;

QVector<WbField *> fields = node->fieldsOrParameters();
foreach (WbField *field, fields) {
foreach (WbField *field, node->fieldsOrParameters()) {
if (!field->alias().isEmpty())
return true;
}
Expand Down Expand Up @@ -296,7 +295,10 @@ void WbTemplateManager::regenerateNode(WbNode *node, bool restarted) {

bool ancestorTemplateRegeneration = upperTemplateNode != NULL;
if (node->isProtoParameterNode()) {
const QVector<WbField *> &parentFields = parent->fieldsOrParameters();
// internal PROTO child could be regenerated due to a parameter exposed in the parent PROTO node
// so for parent PROTO instances both fields and parameters needs to be checked
const QList<WbField *> parentFields = (parent->isProtoInstance() ? parent->parameters() : QList<WbField *>())
<< parent->fields();
foreach (WbField *const parentField, parentFields) {
if (parentField->type() == WB_SF_NODE) {
WbSFNode *sfnode = static_cast<WbSFNode *>(parentField->value());
Expand All @@ -311,9 +313,11 @@ void WbTemplateManager::regenerateNode(WbNode *node, bool restarted) {
regenerateNode(upperTemplateNode);
return;
}
break;
}
} else if (parentField->type() == WB_MF_NODE) {
WbMFNode *mfnode = static_cast<WbMFNode *>(parentField->value());
bool found = false;
for (int i = 0; i < mfnode->size(); ++i) {
WbNode *n = mfnode->item(i);
if (n == node) {
Expand All @@ -328,9 +332,12 @@ void WbTemplateManager::regenerateNode(WbNode *node, bool restarted) {
regenerateNode(upperTemplateNode);
return;
}
found = true;
break;
}
}
if (found)
break;
}
}
} else {
Expand Down

0 comments on commit 6af2bcb

Please sign in to comment.