openigtlink / OpenIGTLink

Free, open-source network communication library for image-guided therapy
http://openigtlink.org
BSD 3-Clause "New" or "Revised" License
103 stars 184 forks source link

Point Message Unpack() yields Bus Error #176

Open Kygandomi opened 6 years ago

Kygandomi commented 6 years ago

Hello,

We are running an OpenIGTLink Server on an sbRIO-9651 module running real time linux and we are running into a bus error when a point message is sent from 3D Slicer (or other external OpenIGTLink clients).

The server has been able to reliably receive transform data and other IGTLink data types such as String and Status, but point message throws a bus error specifically when the Unpack() method is called in the following code. Is there something I am missing ?

Eigen::Vector3d OpenIGTLink::ReceivePoint(igtl::Socket * socket, igtl::MessageHeader * header) {
    // Create a message buffer to receive transform data
    igtl::PointMessage::Pointer pointMsg;
    pointMsg = igtl::PointMessage::New();
    pointMsg->SetMessageHeader(header);
    pointMsg->AllocatePack();

    socket->Receive(pointMsg->GetPackBodyPointer(), pointMsg->GetPackBodySize());

    int c = pointMsg->Unpack(); // This line throws a Bus Error

    Eigen::Vector3d pointData(-1, -1, -1);
    if (c & igtl::MessageHeader::UNPACK_BODY) {
        // Retrieve the point data
        igtlFloat32 x, y, z;
        igtl::PointElement::Pointer point;
        point = igtl::PointElement::New();
        pointMsg->GetPointElement(0, point);
        point->GetPosition(x, y, z);
        pointData(0) = x;
        pointData(1) = y;
        pointData(2) = z;
    }

    return pointData;
}
adamrankin commented 6 years ago

This is probably unrelated to your bug, but I highly recommend you use the igtl::MessageFactory for creating messages.

This ensures messages are created properly and ready for use. This may circumvent your bug.

Kygandomi commented 6 years ago

@adamrankin That sounds like a good idea to try. Do you know where I can find an example of how to setup igtl::MessageFactory to receive data?

adamrankin commented 6 years ago

Some code excerpted from https://github.com/IGSIO/UWPOpenIGTLink/blob/master/UWPOpenIGTLink/Content/IGTClient.cxx#L858

m_igtlMessageFactory = igtl::MessageFactory::New();
...
auto headerMsg = m_igtlMessageFactory->CreateHeaderMessage(IGTL_HEADER_VERSION_1);
...
numOfBytesReceived = SocketReceive(headerMsg->GetBufferPointer(), headerMsg->GetBufferSize());
...
int c = headerMsg->Unpack(1);
...
igtl::MessageBase::Pointer bodyMsg = nullptr;
try
{
  bodyMsg = m_igtlMessageFactory->CreateReceiveMessage(headerMsg);
}
catch (const std::exception&)
{
...
}
...
if (typeid(*bodyMsg) == typeid(igtl::TrackedFrameMessage))
{