CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Join Date
    Mar 2009
    Posts
    14

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Plasmator View Post
    Aye.
    Yes, this was evident from your first post.
    Oh Yeah.....

    So how do I set it up?
    Last edited by Escapetomsfate; March 17th, 2009 at 02:58 PM.

  2. #17
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Escapetomsfate View Post
    Oh Yeah.....

    So how do I set it up?
    Below are links to a short movie (recorded on a test VM; quality should be acceptable) that illustrates one of the methods that I was talking about.
    You may also need VMware's Movie Decoder if you don't have one of their products installed.

    Hopefully you'll be able to do this on your own from now on...

    Debugger.7z (~700 kB)
    http://plasmator.t35.com/DebuggerSFX.zip (Can't link this one, retarded host) [7-zip Self-Extracting Archive] (~800 kB)

  3. #18
    Join Date
    Mar 2009
    Posts
    14

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Plasmator View Post
    Below are links to a short movie (recorded on a test VM; quality should be acceptable) that illustrates one of the methods that I was talking about.
    You may also need VMware's Movie Decoder if you don't have one of their products installed.

    Hopefully you'll be able to do this on your own from now on...

    Debugger.7z (~700 kB)
    http://plasmator.t35.com/DebuggerSFX.zip (Can't link this one, retarded host) [7-zip Self-Extracting Archive] (~800 kB)
    Thanks plasmator, really helpful

    I really don't know which window shows what the problem is. This is the registers window;
    Code:
    EAX = 00079D40 EBX = 00079B30 ECX = 00079D18 EDX = 00000000 ESI = 0178743C EDI = 0007A7BB EIP = 00000000 
    ESP = 00A9FE40 EBP = 00000000 EFL = 00200202
    and this is from output:

    Code:
    First-chance exception at 0x00000000 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.
    Unhandled exception at 0x00000000 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.
    Does anyone know wha that could mean, in relation to the code at the start?

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Escapetomsfate View Post
    Code:
    First-chance exception at 0x00000000 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.
    Unhandled exception at 0x00000000 in orbiter.exe: 0xC0000005: Access violation reading location 0x00000000.
    Does anyone know wha that could mean, in relation to the code at the start?
    You are accessing an address via pointer for reading, and that address you're attempting to access is NULL (0x00000000).

    Set a breakpoint on the very first line of your application, and keep your eye on the Output Window. If that message hasn't appeared when the first line is about to execute, single step through the program until that message appears. When that message appears, then that area of code is where it's triggering that message.

    Usually reading from a NULL address isn't fatal, but irritating seeing that message. The fatal one is when you attempt to write to a NULL address.

    If that message appears before the first line in your main() program, then either you have global classes, objects, that were instantiated, and that is the cause of the problem, or if you're using other DLL's that get loaded at app startup, then they could be the ones causing the problem. You need to just debug slowly to pinpoint where that message is being generated from.

    BTW, since you are using Visual C++, you should have posted this in either the Visual C++ forum (if using MFC) or the Windows API forum (if you're using straight Windows API calls).

    Regards,

    Paul McKenzie

  5. #20
    Join Date
    Mar 2009
    Posts
    14

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Paul McKenzie View Post
    You are accessing an address via pointer for reading, and that address you're attempting to access is NULL (0x00000000).

    Set a breakpoint on the very first line of your application, and keep your eye on the Output Window. If that message hasn't appeared when the first line is about to execute, single step through the program until that message appears. When that message appears, then that area of code is where it's triggering that message.

    Usually reading from a NULL address isn't fatal, but irritating seeing that message. The fatal one is when you attempt to write to a NULL address.

    If that message appears before the first line in your main() program, then either you have global classes, objects, that were instantiated, and that is the cause of the problem, or if you're using other DLL's that get loaded at app startup, then they could be the ones causing the problem. You need to just debug slowly to pinpoint where that message is being generated from.

    BTW, since you are using Visual C++, you should have posted this in either the Visual C++ forum (if using MFC) or the Windows API forum (if you're using straight Windows API calls).

    Regards,

    Paul McKenzie
    Thanks for the help. I already know that this is the code causing the CTD:

    Code:
    DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
    {
    
    	//loop through all weapons, and destroy them.
    for (vector<Weapon>::iterator it = WeaponList.begin(); it != WeaponList.end();++it)
      {
    	  it->explode();
    	}
    }
    So, I suppose I have to assign it to something. Any suggestions?

    EDIT: Could this be it? it is in the Weapon class constructor.

    Code:
    //add self to WeaponList vector.
    WeaponList.push_back(*this);
    Last edited by Escapetomsfate; March 18th, 2009 at 01:24 PM.

  6. #21
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Escapetomsfate View Post
    Thanks for the help. I already know that this is the code causing the CTD:
    There are several lines posted there. Which one is it that is causing the problem?

    As others pointed out, we need to see the full context of when, where, and how that code is called, we do not know what the values of any of those variables are when that code is called, etc.

    Since this is a runtime issue, we can't do static analysis of source code to show you what you're doing wrong. All we can say is that the loop syntactically is correct. If WeaponList is valid, and if explode() has no issues, then that code is correct (Note the if -- only you know whether any of those things are valid or not).

    Regards,

    Paul McKenzie

  7. #22
    Join Date
    Mar 2009
    Posts
    14

    Re: Vector, class, and iterator issues

    I only get an error when I use a function of the iterator (it, using Weapon class functions).

    How do I make a class push back itself on construction? I'm sure that's the problem.

  8. #23
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Escapetomsfate View Post
    EDIT: Could this be it? it is in the Weapon class constructor.

    Code:
    //add self to WeaponList vector.
    WeaponList.push_back(*this);
    You're adding a copy of a not yet constructed object to a vector. Could very well be a problem especially since you seem to have no copy constructor defined for the Weapon class that has some pointer members.
    Kurt

  9. #24
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Vector, class, and iterator issues

    Quote Originally Posted by Escapetomsfate View Post
    I only get an error when I use a function of the iterator (it, using Weapon class functions).
    Then that loop would never execute if the WeaponList is empty. Look at the for loop constraints. Second, if that loop did execute, that means that the WeaponList is not empty, and one of the item's in that list has an explode() function that is buggy, or the item itself is buggy.
    How do I make a class push back itself on construction?
    I don't understand your question. How would that fix the issue I stated above?
    I'm sure that's the problem.
    Hopefully you are not guessing at what the problem is. You never should guess, you have to actually debug, find the cause of the problem, and then offer a diagnosis to fix the problem.

    Regards,

    Paul McKenzie

  10. #25
    Join Date
    Mar 2009
    Posts
    14

    Re: Vector, class, and iterator issues

    Quote Originally Posted by ZuK View Post
    You're adding a copy of a not yet constructed object to a vector. Could very well be a problem especially since you seem to have no copy constructor defined for the Weapon class that has some pointer members.
    Kurt
    Of course! duh! Thanks a lot.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured