I am facing segmentation fault when I'm doing memcpy():
case 32:
std::cout<<"ARVRPipe: RECEIVED_MAP_ROUTE_PACKET_RESULTS"<<std::endl;
memcpy(&(mCommonMessagePtr->maproutePacket), inputBuffer, inputBufferSize);
received_data.path_size = mCommonMessagePtr->maproutePacket.path_size;
std::cout<<"Path Size : " <<received_data.path_size<<std::endl;
received_data.instruction_size = mCommonMessagePtr->maproutePacket.instruction_size;
std::cout<<"Instruction Size : " <<received_data.instruction_size<<std::endl;
if (mCommonMessagePtr && !mCommonMessagePtr->maproutePacket.path.empty()) {
if (mCommonMessagePtr->maproutePacket.path.size() == received_data.path_size) {
std::cout<<"Inside If condition : "<<std::endl;
received_data.path.resize(received_data.path_size);
size_t path_coor_size = received_data.path.size();
std::cout<<"Size of received_data path : "<<path_coor_size<<std::endl;
// Segmentation fault in the below line
memcpy(received_data.path.data(), mCommonMessagePtr->maproutePacket.path.data(), path_coor_size* sizeof(std::pair<double, double>));
// Print out path coordinates
for (const auto& coord : received_data.path) {
std::cout << "Coordinate : " << coord.first << " --- " << coord.second << std::endl;
}
} else {
std::cerr << "Error: Size mismatch between mCommonMessagePtr->maproutePacket.path and received_data.path_size" << std::endl;
}
}
so this received_data and maproutePacket both are object to the same structure given below:
struct ReceivedData
{
int path_size;
int instruction_size;
std::vector<std::pair<double, double>> path;
double distance;
std::vector<Instruction> instructions;
double time;
};
when I do memcpy() it shows segmentation fault in the below line:
memcpy(received_data.path.data(), mCommonMessagePtr->maproutePacket.path.data(), path_coor_size* sizeof(std::pair<double, double>));