C++ optimization may cause some factories to not be registered
Consider the following (real) code:
Eigen::VectorXs extrinsics(7); extrinsics << 0,0,0, 0,0,0,1;
IntrinsicsCameraPtr params = std::make_shared<IntrinsicsCamera>();
params->width = 640;
params->height = 480;
params->pinhole_model_raw << 321, 241, 321, 321;
params->pinhole_model_rectified << 320, 240, 320, 320;
params->distortion = Eigen::Vector3s( 0, 0, 0 );
// Wolf problem
ProblemPtr problem = Problem::create("PO", 3);
// Install camera
auto sen = problem->installSensor("CAMERA", "camera", extrinsics, params);
ASSERT_NE(sen, nullptr);
SensorCameraPtr cam = std::static_pointer_cast<SensorCamera>(sen);
ASSERT_NE(cam, nullptr);
ASSERT_EQ(cam->getImgWidth(), 640);
This code snippet belongs to a test in the vision plugin. When one executes this test, one expects libwolf.so
to be loaded, and thus registering all the factory methods, and also expects libwolfvision.so
to be loaded and thus registering sensor_camera
into the factory. But, since cam->getImgWidth()
is implemented in the .h file, C++ correctly determines that libwolfvision.so
is not needed, and thus is not loaded resulting in sensor_camera
being unregistered and making problem->installSensor("CAMERA", "camera", extrinsics, params);
fail.
This is not an issue to be fixed (or maybe it is), but something to keep in mind. The .so
file will not be loaded unless strictly required by the code.
Edited by Joaquim Casals Buñuel