July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

Debug Error

 

When I’m debugging my code I get the following error message:

*Debug Error!

Program: c:\code\BDB\debug\BDB.exe
Module: 4.5.0
File: global\qglobal.cpp
Line: 1994

ASSERT failure in QVector<T>::operator[]: “index out of range”, fiel c:\qt\4.5.0\src\corelib\tools\qvector.h, line 335

(Press Retry to debug the application)*

I also get the same error (for 4.7.3) at home with a totally different program. At home I can trace it back to adding values to a QVector (the call stack on the work program doesn’t provide as much information). I’m using push_back in both instances, but at work I tried just adding values to vector[i] where “i” is incremented as the code progresses.

Anyone know what’s going on? Also, I had the error at home on Friday night, then on Saturday my code ran fine with no changes made.

10 replies

July 25, 2011

koahnig koahnig
Area 51 Engineer
2881 posts
pbhuter wrote:
Also, I had the error at home on Friday night, then on Saturday my code ran fine with no changes made.

Based on this information I would suggest doing a complete rebuild of your sources affected.
This may cure already your problem.

pbhuter wrote:
I also get the same error (for 4.7.3) at home with a totally different program. At home I can trace it back to adding values to a QVector (the call stack on the work program doesn’t provide as much information). I’m using push_back in both instances, but at work I tried just adding values to vector[i] where “i” is incremented as the code progresses.

In case you are accessing through vector[i] you value i is out of the definition range of your vector. You can check with size [doc.qt.nokia.com] the actual bounds.
For push_back all should be cared off. Again, may be after complete rebuild the problem might be gone. So, if it does not ages to recompile, it is probably the best advise.

July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

I just cleaned and rebuilt the solution. Did the same thing multiple times at home last night. I would pre-allocate a size for my QVector, but I don’t know how big (or small) it needs to be.

July 25, 2011

koahnig koahnig
Area 51 Engineer
2881 posts

You can also use append instead of push_back [doc.qt.nokia.com] it should provide the same functionality but seem to be the method designed for Qt’s QVector.
I doubt that this should make any difference. The explanation sais that it is extending the vector by one field. So either you run out of memory or you are doing somewhere something completely wrong (e.g. a wild pointer) and that is just showing at this point.

It is more than a bit strange that you are reporting this for two independend implementations and also with two non-neighboring versions.

Did you clean your objects by hand? Or did you use just the rebuild button of your IDE?

July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

I clicked “Clean” then “Build” in VS2005 at work and VS2010 at home.

I gave “append” a try with the same result as you expected.

I’m using:

  1. _range.push_back(firstLine[1].toDouble());

where _range is a QVector<double>.

July 25, 2011

koahnig koahnig
Area 51 Engineer
2881 posts

Well “Clean” and “Build” should do. In case of a really strange occassion, you could make sure that all objects are deleted. I assume that you have all in one solution. So, also all libs, if there are some, are deleted an build again.

By reading you code line comes up another possibility. What is firstline? If this is a QVector (of QStrings), this may have triggered also the error message. So, is this element available?

July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

firstLine is a QString

I built a completely new project and inserted the files from the old project. It seems to have cleared up the issue (although I’m not 100% certain since I now have a different issue from a point earlier in the code). This is a potential workaround, but my project at home is much bigger and more complicated. I will try the same solution at home, and post back if it works.

July 25, 2011

koahnig koahnig
Area 51 Engineer
2881 posts
pbhuter wrote:
  1. _range.push_back(firstLine[1].toDouble());

Do you use this construct also in your other project?

What are you trying to achieve with:

  1. firstLine[1].toDouble()

That still looks dubious to me.

July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

I read an input file and parse it as follows:

  1. // create QFile, and open and initialize QTextStream
  2.   QFile infile(_filename);
  3.   if (!(infile.open(QIODevice::ReadOnly)))
  4.   {
  5.     return 1;
  6.   }
  7.  
  8.   QTextStream its(&infile;);
  9.  
  10.   // parse header
  11.   bool dataRow = false;
  12.  
  13.   QString line;
  14.  
  15.   while (!dataRow && !its.atEnd())
  16.   {
  17.     line = its.readLine();
  18.  
  19.     if (line.contains(QRegExp("\\d+\\.?\\d*"))) // check for data row
  20.     {
  21.       dataRow = true;
  22.     }
  23.   } //should have first row of data
  24.  
  25.   QStringList firstLine  = line.split("\t", QString::SkipEmptyParts);

Then I put each component of firstLine into QVectors (sorry, it firstLine is actually a QStringList, not a QString).

When I first got this error at home, I was using the same method of reading an input file. It cleared up for some reason (totally unknown to me), but the manifested itself again last night when I was using push_back to add individual accelerations to a QVector of accelerations.

July 25, 2011

koahnig koahnig
Area 51 Engineer
2881 posts

Ok. That is making sense.
So firstline is a QStringList not just a string.
Even so I expect that it should have a different error message, you might want to check the existence of firstLine1 before using it. That save you some debug time just in case.

July 25, 2011

pbhuter pbhuter
Lab Rat
32 posts

Turns out that it wasn’t a push_back error. I got debugging running and discovered that I was trying to call parts of a QVector that didn’t exist, elsewhere in the code. My file reader wasn’t working because it couldn’t find the input file, so it was kicking out of the reader. Now I need to go home and figure out where in the code I’m accessing non-existent entities of a QVector.

Thanks for all the suggestions and your patience guys. I figure that eventually I’ll know enough to do this programming thing without the aid of others. Until then, I’ll be asking colleagues at work and posting to forums.

 
  ‹‹ Qss in widget      How to correctly kill plugins with their windows? ››

You must log in to post a reply. Not a member yet? Register here!