From 773798b4978e6462d06298dbe63198e05b0e866a Mon Sep 17 00:00:00 2001 From: Lorenzo Garattoni Date: Thu, 21 Sep 2017 11:06:18 +0200 Subject: [PATCH] Fixed potential memory leaks and errors --- src/plugins/robots/e-puck/simulator/epuck_entity.cpp | 2 +- .../robots/e-puck/simulator/epuck_rab_equipped_entity.h | 2 +- .../simulator/epuck_range_and_bearing_default_sensor.cpp | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/robots/e-puck/simulator/epuck_entity.cpp b/src/plugins/robots/e-puck/simulator/epuck_entity.cpp index 99deca3..c9d62da 100644 --- a/src/plugins/robots/e-puck/simulator/epuck_entity.cpp +++ b/src/plugins/robots/e-puck/simulator/epuck_entity.cpp @@ -167,7 +167,7 @@ CEPuckEntity::CEPuckEntity(const std::string& str_id, m_pcOmnidirectionalCameraEquippedEntity = new COmnidirectionalCameraEquippedEntity(this, "omnidirectional_camera_0", ToRadians(cAperture), - CVector3(0.0f, 0.0f, OMNIDIRECTIONAL_CAMERA_ELEVATION)); + CVector3(0.0f, 0.0f, OMNIDIRECTIONAL_CAMERA_ELEVATION),CQuaternion().FromEulerAngles(CRadians::ZERO,CRadians::ZERO,CRadians::ZERO)); AddComponent(*m_pcOmnidirectionalCameraEquippedEntity); /* IRCom equipped entity */ diff --git a/src/plugins/robots/e-puck/simulator/epuck_rab_equipped_entity.h b/src/plugins/robots/e-puck/simulator/epuck_rab_equipped_entity.h index 08d282f..6afb26a 100644 --- a/src/plugins/robots/e-puck/simulator/epuck_rab_equipped_entity.h +++ b/src/plugins/robots/e-puck/simulator/epuck_rab_equipped_entity.h @@ -46,7 +46,7 @@ class CEpuckRABEquippedEntity : public CRABEquippedEntity { Real f_range, SAnchor& s_anchor, CEmbodiedEntity& c_entity_body, - const CVector3& c_position = CVector3(), + const CVector3& c_position = CVector3(0,0,0), const CQuaternion& c_orientation = CQuaternion().FromEulerAngles(CRadians::ZERO,CRadians::ZERO,CRadians::ZERO)); diff --git a/src/plugins/robots/e-puck/simulator/epuck_range_and_bearing_default_sensor.cpp b/src/plugins/robots/e-puck/simulator/epuck_range_and_bearing_default_sensor.cpp index 2c8a67e..b84e2f4 100644 --- a/src/plugins/robots/e-puck/simulator/epuck_range_and_bearing_default_sensor.cpp +++ b/src/plugins/robots/e-puck/simulator/epuck_range_and_bearing_default_sensor.cpp @@ -149,8 +149,12 @@ void CEPuckRABDefaultSensor::Update() { /*let's copy the entities in a proper data structure in a random order.*/ for(CSet::iterator itRABSendingEquipedEntity = setRABs.begin(); itRABSendingEquipedEntity != setRABs.end(); ++itRABSendingEquipedEntity) { - size_t selectedIndex=m_pcRNG->Uniform(CRange(0,indexes.size())); - vRABentities[indexes.at(selectedIndex)]=static_cast(*itRABSendingEquipedEntity); + size_t selectedIndex=indexes.size(); + // Changed because of bug on cluster. To be fixed + while(selectedIndex >= indexes.size()){ + selectedIndex=m_pcRNG->Uniform(CRange(0,indexes.size())); + } + vRABentities[indexes.at(selectedIndex)]=static_cast(*itRABSendingEquipedEntity); indexes.erase(indexes.begin()+selectedIndex); } UInt32 unMessagesNeeded=m_uMaxNumberOfMessages;