generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: help me with C++ grad project

Previous Thread :: Next Thread 
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 07:50 PM
pastebin
/RYv4zVMZ

The problem is within the while loop in main. The object is not being removed from the list when the bunny dies. I'm getting an ACCESS_VIOLATION and I assume this has to do with the iterator not being 'updated' and trying to access the deleted object. I'm not sure I know how to fix this and Stackoverflow didn't provide any clear answer.

Help?
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 08:31 PM
Anypony?
Report Abuse
Robloxianof07 is not online. Robloxianof07
Joined: 30 Jul 2012
Total Posts: 896
11 Aug 2012 08:32 PM
>anypony

Stop.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 08:33 PM
You just won't help me because you don't understand C++.
Report Abuse
raikou6 is not online. raikou6
Joined: 23 Jan 2011
Total Posts: 48
11 Aug 2012 08:34 PM
no bcuz we r lazy

gosh


man


blah
Report Abuse
chickenman158 is not online. chickenman158
Joined: 18 Jan 2011
Total Posts: 915
11 Aug 2012 08:45 PM
If you are getting errors on your grad project, then ask someone else to fix it, I hope you fail.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 08:47 PM
There is no error, it's an access violation. And no, this is the C++ tutorial graduation project. I'm only 13, they would not allow me in any college.
Report Abuse
Robloxianof07 is not online. Robloxianof07
Joined: 30 Jul 2012
Total Posts: 896
11 Aug 2012 08:47 PM
"im only 13"

Lol.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 08:50 PM
No wonder you guys just troll; you know nothing. >_>
I guess that's what I should just expect.

Besides, I fixed it already. erase returns an iterator to the following object, so you can just assign that to iter. Thanks for nothing.
Report Abuse
CoastSniper is not online. CoastSniper
Joined: 07 Mar 2012
Total Posts: 60
11 Aug 2012 08:56 PM
@ROBLOX
you going to complain that im 11?
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 09:05 PM
Yes.
Report Abuse
CoastSniper is not online. CoastSniper
Joined: 07 Mar 2012
Total Posts: 60
11 Aug 2012 09:32 PM
Lol, he is?

That is like racism, I'm also mexican.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 09:33 PM
im mexican too!
Report Abuse
sorcusSUXX is not online. sorcusSUXX
Joined: 09 Aug 2012
Total Posts: 5
11 Aug 2012 09:34 PM
LOL! No comment.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
11 Aug 2012 09:35 PM
awh sorcus! you got me you amazingly hotttattat troll.
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
11 Aug 2012 10:01 PM
First of all, while not related to your problem...

(*iter).newDay();

There's a cleaner way to do this.

iter->newDay();

Anyways, I used Microsoft's handy debugger from Visual Studio to step through the code to find your problem. Since for loops increment before they evaluate whether to keep running, and since the iterator ends up pointing to the end of the list, attempting to increment it returns an error. The way to fix this is to simply add a check after the line where you erase it from the list as to whether or not you've reached the end of the list, and break out of the loop if you have.

Also, as a note, you never add any more rabbits to the list later on despite creating functions for it, there's only that one, and when it dies it gets kinda boring.
Report Abuse
chickenman158 is not online. chickenman158
Joined: 18 Jan 2011
Total Posts: 915
11 Aug 2012 11:41 PM
Access violations are bugs bro.
Since you are the same age as me, and since it is not a crucial exam/final, I will compile the code tomorrow and fix the error.
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
12 Aug 2012 12:03 AM
@Chickenman: I already posted the solution. It's a problem with a lack of bounds checking before continuing the loop.
Report Abuse
Tarabukka is not online. Tarabukka
Joined: 18 Jan 2011
Total Posts: 394
12 Aug 2012 07:26 AM
>complaining that modifying an STL container invalidates all iterators

If you are getting bugs due to that, please rethink how you're doing things. It shouldn't happen.
Report Abuse
thelastbunny is not online. thelastbunny
Joined: 07 Aug 2009
Total Posts: 2879
12 Aug 2012 09:24 AM
Stopped reading at "pony"
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
12 Aug 2012 10:32 AM
A better way is to not increment the loop in the top of the loop, so it would be simply

for(iter = b1.begin(); iter != b1.end();{

then have

if((*iter).getAge() > 10) {
std::cout << (*iter).getName() << " has died." << std::endl;
iter = b1.erase(iter);
}else{
iter++;
}
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image