Skip to content

Commit bf7ec79

Browse files
authored
Merge pull request #301 from randaz81/check_segfault_depth
DepthCamera: added check to prevent a possible segfault
2 parents 6530269 + 829d61a commit bf7ec79

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

plugins/depthcamera/DepthCamera.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ void DepthCamera::Configure(const Entity& _entity,
7575
components::Name(sensorName),
7676
components::Sensor());
7777

78-
auto sdfSensor = _ecm.ComponentData<components::RgbdCamera>(sensor).value().Element();
78+
auto sdfSensS = _ecm.ComponentData<components::RgbdCamera>(sensor);
79+
80+
if (!sdfSensS.has_value())
81+
{
82+
yError() << "gz-sim-yarp-depthcamera-system : the given sensor is not of type='rgbd_camera'";
83+
return;
84+
}
85+
auto sdfSensor = sdfSensS.value().Element();
86+
if (sdfSensor == nullptr)
87+
{
88+
yError() << "gz-sim-yarp-depthcamera-system : sdfSensS.value().Element() is nullptr";
89+
return;
90+
}
91+
7992
//auto A = sensorPippo->getDepthCamera();
8093
auto sdfCamera = sdfSensor->GetElement("camera").get();
8194
auto sdfImage = sdfCamera->GetElement("image").get();

0 commit comments

Comments
 (0)