Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crashes and better warn when getting PROTO #6473

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/changelog-r2023.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Released on XXX XXth, 2023.
- Enabled the launching of MATLAB desktop from the extern launcher ([#6366](https://github.com/cyberbotics/webots/pull/6366)).
- Improved overlays visible in Overlays menu by adding all the robots in the menu list ([#6297](https://github.com/cyberbotics/webots/pull/6297)).
- Bug fixes
- Avoided crash and provided better warnings when attempting to access PROTO nodes in a wrong way from the supervisor API ([#6473](https://github.com/cyberbotics/webots/pull/6473)).
- Fixed errors loading template PROTO if the system user name, the project path, or the temporary directory path contains the `\` character ([#6288](https://github.com/cyberbotics/webots/pull/6288)).
- Fixed Webots and libController version comparison not to take revisions into account ([#6315](https://github.com/cyberbotics/webots/pull/6315)).
- Fixed translation, rotation and scale displayed in the Position tab of the Node viewer in the scene tree ([#6309](https://github.com/cyberbotics/webots/pull/6309)).
Expand Down
16 changes: 13 additions & 3 deletions src/webots/nodes/utils/WbSupervisorUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,15 @@ WbNode *WbSupervisorUtilities::getProtoParameterNodeInstance(int nodeId, const Q
mRobot->warn(tr("%1: node not found.").arg(functionName));
return NULL;
}
return static_cast<WbBaseNode *>(node)->getFirstFinalizedProtoInstance();
WbBaseNode *proto = static_cast<WbBaseNode *>(node)->getFirstFinalizedProtoInstance();
if (!proto) {
if (node->modelName() != node->nodeModelName())
mRobot->warn(
tr("Cannot get the PROTO instance for node '%1' (derived from '%2').").arg(node->usefulName(), node->nodeModelName()));
else
mRobot->warn(tr("Cannot get the PROTO instance for node '%1'.").arg(node->usefulName()));
}
return proto;
}

void WbSupervisorUtilities::changeSimulationMode(int newMode) {
Expand Down Expand Up @@ -594,15 +602,17 @@ void WbSupervisorUtilities::handleMessage(QDataStream &stream) {
stream >> nodeId;
const QString &stateName = readString(stream);
WbNode *const node = getProtoParameterNodeInstance(nodeId, "wb_supervisor_node_load_state()");
node->reset(stateName);
if (node)
node->reset(stateName);
return;
}
case C_SUPERVISOR_NODE_SAVE_STATE: {
unsigned int nodeId;
stream >> nodeId;
const QString &stateName = readString(stream);
WbNode *const node = getProtoParameterNodeInstance(nodeId, "wb_supervisor_node_save_state()");
node->save(stateName);
if (node)
node->save(stateName);
return;
}
case C_SUPERVISOR_NODE_SET_JOINT_POSITION: {
Expand Down
Loading