I created a new controller for Webots in Visual Studio in c ++ (Wizard -> new project controller ...) but when I run the simulation the controller is crashed
this is the code: Basically it is the controller that comes from deafult
#include <webots/DistanceSensor.hpp>
#include <webots/Robot.hpp>
using namespace webots;
int main(int argc, char **argv) {
Robot *robot = new Robot();
int timeStep = (int)robot->getBasicTimeStep();
DistanceSensor *ds = robot->getDistanceSensor("ds_left");
ds->enable(timeStep);
while (robot->step(timeStep) != -1) {
double val = ds->getValue();
};
delete robot;
return 0;
}
After debugging Visual Studio show following WARNING:
Severity Code Description Project File Line Suppression State Warning C26451 Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). Prueba7 C:\PROGRAM FILES\WEBOTS\RESOURCES\LANGUAGES\CPP\ROBOT.CPP 465
And when i tried to use the controller in webots, it shows:
WARNING: Prueba7: The process crashed some time after starting successfully. WARNING: 'Prueba7' controller crashed.