Jump to content
  • Advertisement
Sign in to follow this  
Scanmaster_k

Division by zero

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I got this code:
CCircle *circle = new CCircle(10, 15.0);
circle->getPosition()(rand() % mWindow.getWidth(), rand() % mWindow.getHeight(), 0.0);
circle->getVelocity()(rand() % 10 + 1, rand() % 10 + 1, 0.0);
mCircles.push_back(circle);
When I only create one circle it works fine but whenever I create several I get a division by zero run-time error. Can some one help me why that is? Thanks Scanmaster_K

Share this post


Link to post
Share on other sites
Advertisement
I don't see any division in that code. Run your program through a debugger and post the actual line of code where the error happens.

-me

Share this post


Link to post
Share on other sites
Unless circle->getPosition() and circle->getVelocity() return functors, I'm pretty certain that code is invalid. First of all, are you sure that that is the exact code? Secondly, are you sure that's where the divide by zero errors are coming from?

Share this post


Link to post
Share on other sites
Quote:
Original post by Scanmaster_k
Just noticed that when I take the code oit of the constructor it works fine.

Have you used a debugger to find out exactly where the errors are occuring, yet?

Quote:
Original post by Scanmaster_k
The getPosition returns a reference to a vector class.

And the vector class has the () operator overloaded? Why?

Share this post


Link to post
Share on other sites
The debugger gives the error message at this line:

circle->getPosition()(rand() % mWindow.getWidth(), rand() % mWindow.getHeight(), 0.0);


getWidht and height gives valid return values.

I use the () of my vector class to set the values in the array which hold the data like vec(index, value) or vec(0, 1, 2, 3)

Share this post


Link to post
Share on other sites
Quote:
Original post by Scanmaster_k
The debugger gives the error message at this line:

circle->getPosition()(rand() % mWindow.getWidth(), rand() % mWindow.getHeight(), 0.0);


getWidht and height gives valid return values.

I use the () of my vector class to set the values in the array which hold the data like vec(index, value) or vec(0, 1, 2, 3)


So you are using it to set the position? A setPosition method would be a lot easier to read.

EDIT: Additionally, is that as deep as the error goes? It doesn't occur in the function called?

Share this post


Link to post
Share on other sites
Yeah I actually agree but this is an old class I did and I was lazy and all of those kinds of excuses.

Don't think so, as it works fine when I take it out of my initialize function, it's just weird.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!