Skip to content

Commit

Permalink
Fix Bounding Box Initialization when a Geometry is Inserted into a Sh…
Browse files Browse the repository at this point in the history
…ape (#6691)

* don't set ode data when creating geometry

* assert that a new geometry is used for setOdeData

* deduplication

* update changelog
  • Loading branch information
CoolSpy3 authored Oct 30, 2024
1 parent a62a005 commit 3e3c521
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Released on December **th, 2023.
- Fixed error on macos when when putting displays and cameras in separate windows ([#6635](https://github.com/cyberbotics/webots/pull/6635)).
- Fixed crash when `wb_supervisor_field_get_name` was called with NULL ([#6647](https://github.com/cyberbotics/webots/pull/6647)).
- Fixed bug where the wrong y coordinate was used for one corner of the box drawn to represent a box-plane collision ([#6677](https://github.com/cyberbotics/webots/pull/6677)).
- Fixed a bug where Webots would crash if a geometry was inserted into a `Shape` node used a bounding box ([#6691](https://github.com/cyberbotics/webots/pull/6691)).
2 changes: 1 addition & 1 deletion src/webots/nodes/WbGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void WbGeometry::setOdeMass(const dMass *mass) {
}

void WbGeometry::setOdeData(dGeomID geom, WbMatter *matterAncestor) {
assert(geom && matterAncestor);
assert(geom && geom != mOdeGeom && matterAncestor);

if (!areOdeObjectsCreated())
createOdeObjects();
Expand Down
18 changes: 4 additions & 14 deletions src/webots/nodes/WbMatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ dGeomID WbMatter::createOdeGeomFromGeometry(dSpaceID space, WbGeometry *geometry
dGeomID geom = geometry->createOdeGeom(space);

if (geom && setOdeData) {
// Stores a pointer to the ODE geometry into the WbGeometry node & sets the WbGeometry node and its WbMatter parent node as
// reference data
geometry->setOdeData(geom, this);
connect(geometry, &WbGeometry::boundingGeometryRemoved, this, &WbMatter::removeBoundingGeometry, Qt::UniqueConnection);
}
Expand Down Expand Up @@ -333,16 +335,7 @@ dGeomID WbMatter::createOdeGeomFromPose(dSpaceID space, WbPose *pose) {
if (eg) // TODO: rename slot?
connect(eg, &WbElevationGrid::validElevationGridInserted, pose, &WbPose::geometryInPoseInserted, Qt::UniqueConnection);

dGeomID geom = createOdeGeomFromGeometry(space, geometry, false);
if (geom == NULL)
return NULL;

// Stores a pointer to the ODE geometry into the WbGeometry node & sets the WbGeometry node and its WbMatter parent node as
// reference data
geometry->setOdeData(geom, this);
connect(geometry, &WbGeometry::boundingGeometryRemoved, this, &WbMatter::removeBoundingGeometry, Qt::UniqueConnection);

return geom;
return createOdeGeomFromGeometry(space, geometry);
}

void WbMatter::createOdeGeomFromInsertedPoseItem() {
Expand Down Expand Up @@ -382,10 +375,7 @@ void WbMatter::createOdeGeomFromInsertedShapeItem() {
assert(ifs || eg);
return;
}
// Stores a pointer to the ODE geometry into the WbGeometry node & sets the WbGeometry node and its WbMatter parent node as
// reference data
geometry->setOdeData(insertedGeom, this);
connect(geometry, &WbGeometry::boundingGeometryRemoved, this, &WbMatter::removeBoundingGeometry, Qt::UniqueConnection);

setGeomMatter(insertedGeom, geometry);
}

Expand Down

0 comments on commit 3e3c521

Please sign in to comment.