Results 1 to 11 of 11

Thread: runtime error

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default runtime error

    Hi,
    I coded that loop and get me the attach error. What's wrong? (trace debug shows me the runtime-error on 'return 0' )
    thanks.
    Qt Code:
    1. int main (int argc, char** argv) {
    2. ......................
    3. vector<Unit> u(lines);
    4. cout << "Weight " << u[0]._weight << " " << u[1]._weight << " " << u[2]._weight << "\n";
    5. for (int i=0; i < example.size(); i++) {
    6. for (int j=0; j < example[i].size(); j++) {
    7. if (j < example[i].size() -1) {
    8. u[j]._input = example[i][j];
    9. cout << u[j]._input << endl;
    10. }
    11. else
    12. u[j]._target = example[i][j]; //without this nothing problem (?)
    13. //u[j]._input = example[i][j]; //with this no problem!
    14. }
    15. printf("\n");
    16. }
    17. return 0;
    18. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    I see that real error is from the comment line under here:
    Qt Code:
    1. vector < vector <float> > example;
    2. char ch;
    3. string s="";
    4. vector <float> line;
    5. while (f.readChar(ch)) {
    6. if (ch == '\n') {
    7. lines++;
    8. line.push_back( atof(s.c_str()));
    9. example.push_back(line);
    10. line.clear();
    11. s="";
    12. }
    13. else
    14. if (ch != ' ') {
    15. s += ch;
    16. }
    17. else {
    18. //line.push_back( atof(s.c_str())); //the error is here....
    19. s="";
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Am I using that vector in a wrong way?
    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: runtime error

    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.

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    with
    Qt Code:
    1. line.push_back( 2.0f );
    To copy to clipboard, switch view to plain text mode 
    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?
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: runtime error

    Does "example" have a proper size before you access its items?

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    Quote Originally Posted by wysota View Post
    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?
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: runtime error

    Just take a debugger and see where the app crashes. There is no reason to guess when you can just check that.

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    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
    Qt Code:
    1. return HeapValidate( _crtheap, 0, pHdr(pUserData) );
    To copy to clipboard, switch view to plain text mode 
    it crashes . Maybe does vector of vector need a my own destructor?
    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: runtime error

    Quote Originally Posted by mickey View Post
    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...

  10. #10
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    error post
    Regards

  11. #11
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: runtime error

    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?
    Qt Code:
    1. > gd.exe!_CrtIsValidHeapPointer(const void * pUserData=0x00321550) Line 1807 C
    2. gd.exe!_free_dbg(void * pUserData=0x00321550, int nBlockUse=1) Line 1132 + 0x9 C
    3. gd.exe!operator delete(void * pUserData=0x00321550) Line 54 + 0x10 C++
    4. gd.exe!std::allocator<Unit>::deallocate(Unit * _Ptr=0x00321550, unsigned int __formal=3) Line 132 + 0x9 C++
    5. gd.exe!std::vector<Unit,std::allocator<Unit> >::_Tidy() Line 797 C++
    6. gd.exe!std::vector<Unit,std::allocator<Unit> >::~vector<Unit,std::allocator<Unit> >() Line 389 C++
    7. gd.exe!main(int argc=1, char * * argv=0x00321600) Line 77 + 0x19 C++
    8. gd.exe!mainCRTStartup() Line 259 + 0x19 C
    To copy to clipboard, switch view to plain text mode 
    I attach this small program hoping one more hint.
    Attached Files Attached Files
    Regards

Similar Threads

  1. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  3. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  4. Fed up with M$ Window$ !!! Why is Tux leaving me alone???
    By fullmetalcoder in forum General Discussion
    Replies: 35
    Last Post: 18th March 2006, 12:57
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.