Variables with Undefined Values

Started by
17 comments, last by Eleventy 20 years, 10 months ago
Is there any way to check if a variable has an undefined value in C++ before using it. For some reason, I sometimes get the main player's position's x, y, or z values ending up being undefined after doing collision detection. I want to know if I can implement a check to correct this so the player doesn't end up being in infinite space . Thanks. EDIT: Fixed anything that was unclear. My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM [edited by - JoshT172 on May 30, 2003 12:09:58 AM]

Eleventy

Advertisement
undefined variables are compile-time errors. Maybe you mean uninitalized?

If that is the case, default values should be provided in constructors and they should never really be magicly reset. You must be doing something else wrong.


-SniperBoB-
Sorry, i was a bit unclear, i meant that during the game, sometimes the variable will become undefined (divided by zero) - I can tell this since I have a debug feature that lists all the variables and their values - one of the x, y, or z values of the ship will have -1.#IND as it's value, and the screen will go black (since DirectX can't render an object with an undefined location).

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

[edited by - JoshT172 on May 29, 2003 3:33:16 PM]

Eleventy

What you have is a bug. Instead of implementing code to check for it and deal with it at runtime, simply fix the bug - make it so your x,y,z values can never be undefined (divided by zero). Something is hammering your variables: get rid of them hammer, don''t put on extra armour.
Brianmiserere nostri Domine miserere nostri
Yeh, i tried looking over the code - but my collision detection algorithm is so huge that it would take nearly a day! (It's polygon-level collision detection, if anyone wants to know). I'll see what I can do - I was just wondering if I could find an easy way out.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

[edited by - JoshT172 on May 29, 2003 3:54:29 PM]

Eleventy

Put a *temporary* check in for the invalid values, and set a breakpoint in it. Then run your app in the debugger, and you''ll hit your breakpoint when your variable gets nuked. Then trace backwards and figure out why. It shouldn''t take long, and it will be worth it, trust me.
Brianmiserere nostri Domine miserere nostri
Thanks - but, I''ve never used the debugger... I''ll have to read up on that one...

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

Eleventy

You probably would have thought of this, but did you make sure you are assigning values to your variables before using them?

"Skepticism.... that great rot of the intellect." - V.H.
Bah, what does HE know?


Albekerky Software
"Skepticism.... that great rot of the intellect." - V.H.Bah, what does HE know?Albekerky Software
Yeah - I always make my variables have a value of '0.0f' or NULL if no collision occurred.

My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM
We (your friends) will miss you, YodaTheCoda!

[edited by - JoshT172 on May 30, 2003 2:38:01 AM]

Eleventy

quote:Original post by JoshT172
Is there any way to check if a variable has an undefined value in C++ before using it. For some reason, I sometimes get the main player''s position''s x, y, or z values ending up being undefined after doing collision detection. I want to know if I can implement a check to correct this so the player doesn''t end up being in infinite space . Thanks.


There are functions in the C++ library that return NaN or infinity -- std::numeric_limits::quiet_NaN() and std::numeric_limits::infinity(). You can compare your value to the appropriate one of those.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement