Interfacing Qt & Isaac using UDP & Capnp : udp_packetizer.cpp@249: Package index 0/0 ouf of range

Hello,
I’m trying to send a string from Qt to Isaac using TCP but when I do my app throw a bad alloc error because I don’t use any proto.
So now I trying using a pingProto by adapting this Qt app found on github, just changing the proto and port/addresse but just after the start of udp :
INFO engine/alice/components/UdpSubscriber.cpp@67: Starting UDP subscriber on port 6005
I get the following error :
PANIC engine/alice/backend/udp_packetizer.cpp@249: Package index 0/0 ouf of range (this should not be an assert)
I want to do it in TCP but since the code I found use UDP I just want to try UDP before going to TCP.

Any idea why I get this error ?

this is the function in udp_packetizer :

  // Mark the package as received
  const size_t package_index = package_header.getPackageIndex();
  ASSERT(package_index < puzzle.packages_received.size(),
         "Package index %zd/%zd ouf of range (this should not be an assert)",
         package_index, puzzle.packages_received.size());
  {
    if (!puzzle.packages_received[package_index]) {
      puzzle.packages_received[package_index] = true;
    } else {
      LOG_WARNING("Duplicated package %d (this should not be an assert)", package_index);
      return;
    }
  }

in my JSON :

	"udp_rx":{
	"port": 6005,
	 "message_assembly_slot_count":  1
	}

This is my qt UDP sender (no warning displayed in Qt) :

#include "positionsender.h"
#include <QUdpSocket>
#include <QTimer>
#include <QDebug>
#include <capnp/message.h>
#include <capnp/serialize.h>
#include "PingProto.capnp.h"

using ::capnp::word;
using ::kj::ArrayPtr;
typedef ::kj::Array<word> WordArray;

PositionSender::PositionSender(QObject* parent)
    : QObject(parent)
    , m_delayMsec(16) // this works out to ~58.82352941176 Hz
    , m_dest(QHostAddress::LocalHost)
    , m_destPort(6005)
    , m_socket(new QUdpSocket(this))
    , m_sendTimer(new QTimer(this))
{
    connect(m_sendTimer, &QTimer::timeout, this, &PositionSender::sendPosition);
    m_sendTimer->setTimerType(Qt::PreciseTimer);
    initPositions();
}

void PositionSender::initPositions()
{

        ::capnp::MallocMessageBuilder message;
        L3::PingProto::Builder position = message.initRoot<L3::PingProto>();
        position.setMessage("Hello There"); // booogus values

        WordArray array = ::capnp::messageToFlatArray(message);
        ArrayPtr<unsigned char> messageBytes(array.asBytes());
        QByteArray messageBuffer((const char*)messageBytes.begin(), messageBytes.size());
        m_positionBuffers.append(messageBuffer);

}

void PositionSender::setRate(int rateHz)
{
    m_delayMsec = qRound(1000.0/rateHz);
}

void PositionSender::setDestination(QHostAddress dest, quint16 destPort)
{
    m_dest = dest;
    m_destPort = destPort;
}

void PositionSender::start()
{
    m_sendTimer->start(m_delayMsec);
}

void PositionSender::stop()
{
    m_sendTimer->stop();
}

void PositionSender::sendPosition()
{
    static QList<QByteArray>::Iterator bufIter = m_positionBuffers.begin();
    QByteArray& messageBuffer = *(bufIter++);
    if(bufIter == m_positionBuffers.end()) bufIter = m_positionBuffers.begin();

    qint64 bytesSent = m_socket->writeDatagram(messageBuffer, m_dest, m_destPort);
    if (bytesSent < 0)
    {
        qWarning() << qPrintable("Error sending datagram:") << m_socket->errorString();
        return;
    }
    if (bytesSent != messageBuffer.size())
    {
        qWarning() << qPrintable("Partial send") << QString::number(bytesSent) + "/" + QString::number(messageBuffer.size()) << qPrintable("bytes sent");
        return;
    }
}

Thanks !
Regards,
Planktos

When I try with :
position.setMessage("012345678901234");
I get
PANIC engine/alice/backend/udp_packetizer.cpp@249: Package index 0/0 ouf of range (this should not be an assert)

But when I try with :
position.setMessage("0123456789012345");
I get :
terminate called after throwing an instance of 'kj::ExceptionImpl' what(): capnp/layout.c++:2174: failed: expected boundsCheck(segment, ptr, ref->structRef.wordSize()); Message contained out-of-bounds struct pointer. stack: 55a4940a1400 55a49410569d 55a494157265 55a4941574ec 55a49415837e 55a494062917 55a494137565 55a494014c70 7f522c2db6de 7f522c5ae6da 7f522bd36a3e

So an error about packetizer when message<=15 char and an error about capnp when message>=16 char.
That’s weird…

In capnp doc : Cap’n Proto bounds-checks each pointer when it is read and throws an exception or returns a safe dummy value (your choice) if the pointer is out-of-bounds.