ROS Kinetic (and Melodic) generating a Native Crash with Mono when wrapping C# in C++

asked 2021-03-26 12:46:13 -0500

updated 2021-03-27 01:44:44 -0500

gvdhoorn gravatar image

Hello,

I hope the problem that I am experiencing is pertinent to this forum and that you can help me figure out a solution. What basically happens is that I am using C# wrapped in C++ code with ROS kinetic (and I tried the same code with ROS melodic). What happens is that I get a Native Crash Report when I try to run my code. The problem is that this error doesn't occur consistently and there is not a clear explanation in the crashing report of what caused this crash. Well, at least for me it is hard to figure out what is going on. Have you ever heard of this problem with ROS? I posted the same problem in github under Mono 2 months ago, but no response. I also tried to browse internet for days, but no luck. It appears other people are experiencing this type of crash (not necessarily with ROS), but I could not find any good or clear solution. One way that I have to temporarily fix the problem is open the file listener_sp.cpp (which is where C# is wrapped into C++) and then close it after saving it. Not sure why, but that doesn't the trick. Well, at least temporarily. I have tried to attach the code here, but I have got a message saying that I need ">5 points required to upload files". Apologies, but I am not sure what that means, so I am pasting the code of the file listener_sp, which is what is causing problems. As I said, sometimes it crashes, other times it works. The C# library that I am using is: SP_CD_Cpp.dll. I wrote the code of this C# library and when I tested without ROS it was working fine. It never crashed.

//-------------------------------------------------------------------------------------------------------------// //-------------------------------------------------------------------------------------------------------------//

//ROS Libraries
#include "ros/ros.h"
//#include "std_msgs/String.h"
#include "hri_msgs/RecognizedSpeech.h"

#include "knowledge_msgs/PlanningCmdClips.h"
#include "knowledge_msgs/planning_cmd.h"

//Mono Libraries
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/class.h>

//Native C++ Libraries
#include <string>
#include <cstring>
#include <iostream>
#include<vector>

//String used to save the commands that will be sent to CLIPS
std::string save_commands;

//Mono global variables
MonoDomain *domain;
MonoAssembly *assembly;
MonoImage *image;
MonoMethodDesc *TypeMethodDesc;
MonoMethod *method;
MonoClass *SP_class;
MonoObject *SP;
MonoString *input_string;

//ros::ServiceClient srvCltWaitForCommand;
ros::ServiceServer Server_Wait_Command;
bool out_wc = false;    //Bool variable used to check if the service "wait_command" returned success = 1;
ros::ServiceServer Server_Interpretation;
bool out_si = false;    //Bool variable used to check if the service "spr_interpreter" returned success = 1;
ros::ServiceServer Server_Confirmation;
bool out_sc = false;    //Bool variable used to check if the service "confitrmation" returned success = 1;

//----------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------//
//Service "WAIT_COMMAND"
bool method_wait_command(knowledge_msgs::planning_cmd::Request  &req, knowledge_msgs::planning_cmd::Response &res)
{

        out_wc = false;

        //These are the two strings that service "WAIT_COMMAND" needs to receive to move on to the next phase
        std::string params = "ready";
        std::string name = "wait_for_speech";

        //std::cout << "Params: " << req.params << "\n";
        //std ...
(more)
edit retag flag offensive close merge delete