View Full Version : runtime error

10th December 2006, 16:10
I coded that loop and get me the attach error. What's wrong? (trace debug shows me the runtime-error on 'return 0' )

int main (int argc, char** argv) {
vector<Unit> u(lines);
cout << "Weight " << u[0]._weight << " " << u[1]._weight << " " << u[2]._weight << "\n";
for (int i=0; i < example.size(); i++) {
for (int j=0; j < example[i].size(); j++) {
if (j < example[i].size() -1) {
u[j]._input = example[i][j];
cout << u[j]._input << endl;
u[j]._target = example[i][j]; //without this nothing problem (?)
//u[j]._input = example[i][j]; //with this no problem!
return 0;

11th December 2006, 00:23
I see that real error is from the comment line under here:

vector < vector <float> > example;
char ch;
string s="";
vector <float> line;
while (f.readChar(ch)) {
if (ch == '\n') {
line.push_back( atof(s.c_str()));
if (ch != ' ') {
s += ch;
else {
//line.push_back( atof(s.c_str())); //the error is here....

Am I using that vector in a wrong way?

11th December 2006, 12:28
Maybe it's atof() that fails? You're getting an assertion - you might want to check, where exactly it occurs by running your app under a debugger and displaying the strack trace when it asserts.

11th December 2006, 13:53
line.push_back( 2.0f ); fail too! tracing program the windows error appear on return 0 of main(); but I've problem. Idon't know how show the line content (in .NET) while debuggig; if i use line[0] it doesn't show me its content. how this, please?

11th December 2006, 14:23
Does "example" have a proper size before you access its items?

11th December 2006, 23:18
Does "example" have a proper size before you access its items?
but example start with size 0 and I fill 'line'; when file find '\n' carater, I insert 'line' (that is filled eg 3 values) within example with pusk_back()...what do you mean?

11th December 2006, 23:29
Just take a debugger and see where the app crashes. There is no reason to guess when you can just check that.

12th December 2006, 00:07
sorry, maybe I can't understand; jpeg attached previous shows where's the crash; anyway, I can see when the app is ending (on return 0 of the function main) the destructor vectors start and inside file dbgheap.c on instruction

return HeapValidate( _crtheap, 0, pHdr(pUserData) );
it crashes . Maybe does vector of vector need a my own destructor?

12th December 2006, 01:12
sorry, maybe I can't understand; jpeg attached previous shows where's the crash;
No it doesn't. It just states there was an assert because of invalid pointer. A debugger will give you an exact sequence of calls that caused the error.

Maybe does vector of vector need a my own destructor?
Don't guess. std::vector class works for many other people so it will work for you too without modifications. There is an error in your application somewhere, most probably a pointer-based one, so you just have to take a debugger and find it. Knowing a part of code that triggered the assert is not enough if you don't know what (which object and where, in what conditions) called the code. Getting a stack trace will answer that question.

I just don't know why are you defending yourself from using a debugger...

12th December 2006, 20:10
error post

12th December 2006, 20:10
What do you mean for debugging? (.net has debugger); how I said in first post debugging I can see all program is exectuted correct but on "return 1" it crash(this with what I mena for debugging); it seems to me some problem with destructor of the vector of vector but I don't understand why. Is this below the stack trace you mean?

> gd.exe!_CrtIsValidHeapPointer(const void * pUserData=0x00321550) Line 1807 C
gd.exe!_free_dbg(void * pUserData=0x00321550, int nBlockUse=1) Line 1132 + 0x9 C
gd.exe!operator delete(void * pUserData=0x00321550) Line 54 + 0x10 C++
gd.exe!std::allocator<Unit>::deallocate(Unit * _Ptr=0x00321550, unsigned int __formal=3) Line 132 + 0x9 C++
gd.exe!std::vector<Unit,std::allocator<Unit> >::_Tidy() Line 797 C++
gd.exe!std::vector<Unit,std::allocator<Unit> >::~vector<Unit,std::allocator<Unit> >() Line 389 C++
gd.exe!main(int argc=1, char * * argv=0x00321600) Line 77 + 0x19 C++
gd.exe!mainCRTStartup() Line 259 + 0x19 C

I attach this small program hoping one more hint.