Variables with Undefined Values
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]
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-
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]
My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM
[edited by - JoshT172 on May 29, 2003 3:33:16 PM]
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.
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]
My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM
[edited by - JoshT172 on May 29, 2003 3:54:29 PM]
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.
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
My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM
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]
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]
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement