PDA

View Full Version : runtime error <vector>



mickey
22nd July 2006, 11:01
HI, I have a SLOT


slot() {
vector <QWidget*> tabs;
vector<QSpinBox*> sbx;
vector<QSpinBox*> sby;
vector<QSpinBox*> sbz;

cout << "problem \n";
tabs.push_back(tab0);
tabs.push_back(tab1);
tabs.push_back(tab2);
tabs.push_back(tab3);
tabs.push_back(tab4);
tabs.push_back(tab5);
tabs.push_back(tab6);
tabs.push_back(tab7);
cout << " END problem \n";
}
this slot can be called many time; it happen that the 3th or 4th time, generate a bug error;
"cout << " END problem \n";" isn't print..........do anyone know why??? thanks

jacek
22nd July 2006, 14:08
Try cerr instead of cout.

mickey
22nd July 2006, 15:05
sorry wich aim? cerr << "problem "; print exactly the same thing; could you explain me waht you want say?.... ( I knnow at the end of slot() the vector are destroyed.......); the error is a memory read/write error
thanks

jacek
22nd July 2006, 15:45
the error is a memory read/write error
I understood that it doesn't print "END problem". Post the exact error message.

mickey
22nd July 2006, 15:55
nothing error in console; my windows isn't english so I try to traslate you:
1. appear a first message that ask if you want send the problem to microsoft (without specify kind of problem)
2. one message that say:


the istruction "0x7c92103c" has referred to memory at "0x000801b3". The memory couldn't be "written". Click on "ok" to close application


I'm sorry the problem isn't there: I comment all slot() and now I can call it 5 times, after same error; do anyone suggest me what it can be? Or how do I can find it? thanks

jacek
22nd July 2006, 16:55
Or how do I can find it?
Run you application from a debugger and see the stack trace --- it should show you where the problem is.

mickey
25th July 2006, 13:59
Right?


vector <GLfloat*> ppp;
for (int g=0; g < ....; g++) {
GLfloat* position = new GLfloat[4];
for (int i=0; i<4; i++) {
position[i] = ch.toInt(); // split a string as "1543"
}
ppp.push_back(position);
}

for( std::vector<GLfloat*>::iterator i = ppp.begin(); i != ppp.end(); ++i ) {
delete [] *i;
}
ppp.clear();

and how obtain value of fist element array of first element vector?? thanks
hi; the problem seems the delete for of this vector; if I comment it, it don't crash; is there anything wrong ? thanks

helcaraxe
5th September 2006, 11:50
Hej,

You're right, this is the problem.
Try "i++" instead of "++i" in line 10.

If you use ++i, the value in i will be incremented before the body of the loop is executed, leading to a delete with invalid parameter. In fact it is the "*i" in the last call that causes the crash (it is always the last one :)).

You could in those cases increment the iterator in the body of the loop, then you have absolute control what happens why. This is for paranoids - like me ;)

Jan

jacek
5th September 2006, 11:58
If you use ++i, the value in i will be incremented before the body of the loop is executed
No, it won't.

helcaraxe
5th September 2006, 12:11
Then the problem is not in this code snippet :)

jacek
5th September 2006, 12:18
Then the problem is not in this code snippet :)
Yes, that's why a stack trace is necessary. The memory might be deleted twice or accessed after it was deallocated.