ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think the answer given above is correct but incomplete, and was causing me SEGFAULTs on rosserial_embeddedlinux.

Where tsuda did: thermo.layout.dim = (std_msgs::MultiArrayDimension *) malloc(sizeof(std_msgs::MultiArrayDimension) * 2);

dim is a pointer to an object that is getting assigned to the malloc'd memory. (Ignore the fact that twice as much memory is allocated as appears to be needed.) However, the memory malloc'd is allocated but not initialized. Therefore the MultiArrayDimension object's vtable is not initialized, and the subsequent call to thermo_pub.publish( &thermo ); which calls serialize on MultiArrayLayout which calls MultiArrayDimension is using a random vtable pointer when MultiArrayLayout calls this->dim[i].serialize(args...).

tsuda's Arduino would not have segfaulted, but linux does.

The correct implementation is to instantiate a new MultiArrayDimension object with something like: std_msgs::MultiArrayDimension myDim; (this should be done outside of any function, if you need it to persist when the function returns)

tsuda said he got it to work, but maybe not with the code shown here.

Tell me if I'm off in the weeds.

Paul