PDA

View Full Version : ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/qbytearray



vivekyuvan
30th July 2018, 09:25
Hi Friends

I have qtserial port library in my application. my application was previously wriiten in qt4.8.7 with qextserial library.

Now I did upgrade my application code from qextserial to qserial port library and qt 4.8.7 to qt 5.7.0

The problem that I faced here is



ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464




So This code works without issue in previous version qt4.8.7 with qextserial port library


Now I got the error ASSERT : "unit(i) < unint(sisze())


Help me out to resolve this issue


My code is here


My serial port initialize function is here




void MainWindow::SerialPortInit()
{
DataAcquisitionPort = new QSerialPort();
DataAcquisitionPort->setPortName("/dev/ttyUSB0");
DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl); // To set the flow control to none
DataAcquisitionPort->setDataBits(QSerialPort::Data8);
DataAcquisitionPort->setParity(QSerialPort::NoParity);
DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
qDebug() << "PORT Initialize completed";

bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));
if(res)
{
qDebug() << "TRYING TO OPEN PORT";
const char data[] = "PROTOCOL PORT OPEN SUCCESS";
qDebug() << data;
DataAcquisitionPort->write(data, sizeof(data));
const char Protocol_init_data_1[] = { 0x80};
const char Protocol_init_data_2[] = { 0x04 };
const char Protocol_init_data_3[] = { 0x00 };
const char Protocol_init_data_4[] = { 0x80 };
const char Protocol_init_data_5[] = { 0x02 };
const char Protocol_init_data_6[] = { 0x00 };
DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
// Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
// Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
//Sleeper::msleep(100);
QThread::msleep(100);
DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
qDebug() << "PROTOCOL OPEN SUCCESS";
}
else
{
qDebug("PROTOCOL PORT OPEN FAILED");
}
}



And this function for check whether the valid data arrived or not


void MainWindow::Get_Data_from_Serial_port()
{
QByteArray Protocol_Raw_Data;
Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
qDebug() << Protocol_Raw_Data;
if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03"))) // To check for the Complete Frame
{
P1.append(Protocol_Raw_Data);
Protocol_Data_Organize(P1);
P1.clear();
}
else
{
P1.append(Protocol_Raw_Data); // If the frame is not completed, then append the data to Pi array
}
}




And his function for organize the raw data and separate the raw into a single frame


void MainWindow::Protocol_Data_Organize(QByteArray Data)
{
QList <QByteArray> Data_Frame;
for(int pos = 0; pos < Data.size(); pos++)
{
if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
{
Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
}
}
Data_Frame << Data.split(';'); // Splits the Whole data frame into separate individual data frame and stores it in the List
Protocol_Data_split(Data_Frame);
}



My application code Build and compiled successfully but when i run the code application closed unexpectedly



ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
The program has unexpectedly finished.

d_stranz
30th July 2018, 17:17
I think you need to learn to use the debugger. Set breakpoints at the places where you are changing the contents of your QByteArray instances and see if they contain what you think they do. The call stack should tell you exactly where the assert occurs (which may not be where the error is, because something else you do earlier in the code might eventually result in the error that causes the crash).

ado130
31st July 2018, 06:59
Not sure, is this code correct?

for(int pos = 0; pos < Data.size(); pos++)
{
if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
{
Data.insert((pos+1), ';'); // Inserting a Splitter between the individual data frames
}
}


inline char QByteArray::at(int i) const
{ Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }

Especially in the first cycle, when pos = 0. Then in the if condition you are trying to get Data.at(0-1) what means -1 position, this might be the error. Also in the for the last value of pos, when pos = Data.size()-1, then you are trying to get pos+2 what does not exist.

Maybe this can help:

for(int pos = 1; pos < Data.size()-2; pos++)