Jump to content
  • Advertisement
Sign in to follow this  
KnightAdz

[solved]Release build has incorrect behaviour (c++, Visual Studio)

This topic is 2805 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

I have encountered a problem with my latest project, which is that the debug AND release versions will work correctly if run from Visual Studio, but if I run the .exe outside of Visual Studio, a bug occurs.

I have researched the differences between release and debug builds and found that often bugs like this occur due to variables not being initialised properly or because the release version runs faster than the debug version, however I can't see how either of those are affecting this case.

The game is a plane game, where you press space bar to fire missiles. The input is updated, and if the space bar has newly been pressed, I set a bool (bFireMissile) to true:

//If spacebar is pressed
if (input->NewKeyPress(VK_SPACE))
{
//Signal that a missile needs to be fired
m_bFireMissile = true;
}



(I have also tested this with my other function KeyDown which simply returns if a key is held down or not, and the same thing happens.)

Then, when the plane is updated, if bFireMissile is true, a missile is fired and the bool is set to false:

if (m_bFireMissile == true)
{
FireMissile();
m_bFireMissile = false;
}



This is the only time bFireMissile is ever used, so it isn't being altered somewhere else.

What happens outside of Visual Studio is that one, two or sometimes 3 missiles can be fired, and then no more can be fired, no matter how many times you press the space bar. Inside Visual Studio, everytime the space bar is pressed, a missile is fired.

Since the input and update methods are running parallel to each other, I guess the timing aspect could affect it, but as far as I know, shouldn't make any difference to the running of the program.

So my question is basically, does anybody have any suggestions as to what could be causing the game to act differently outside of Visual Studio?

[Edited by - KnightAdz on October 19, 2010 8:53:15 AM]

Share this post


Link to post
Share on other sites
Advertisement
You say the input and update methods are running in parallel. Are you using mutexes? Otherwise as input tries to write to m_bFireMissile then update could also try writing to it at the sametime. If you are WRITING to variables that multiple threads are touching (or even a single thread is writing and others reading) you have to use mutexes to make sure you get the correct data.

Share this post


Link to post
Share on other sites
Actually, I'm not sure if they are running parallel to be honest. The input is updated as part of the WndProc of the window, and I'm not entirely sure when that happens. I don't know what mutexes are, so I'll look them up and see if they can help

Share this post


Link to post
Share on other sites
The WndProc will not run in parallel, but will usually be called inside DispatchMessage. I would add debug-output or breakpoints to check if you ever get input->NewKeyPress(VK_SPACE) to true, as well as other key points, to see where the problem might occur. One possibility is that your program loses focus so you never get WM_KEYDOWN messages, which you can also check by adding debug output on that message.

Share this post


Link to post
Share on other sites
Thanks for the suggestion. By outputting to a log file, I can see that the input is working just fine. In fact, the program thinks it has created a missile (which is a quad made up of two triangles with a texture), however it actually hasn't. So turns out I was barking up the wrong tree. Now I need to figure out why

cMissile* m = new cMissile(this);
m_missiles.push_back(m);

isn't functioning correctly outside of the compiler...

Share this post


Link to post
Share on other sites
Well, I figured it out. Surprise surprise...it was an initialisation error (sigh). I thought I had checked all the relevant values put I was checking the wrong ones. Thanks to the suggestion of logging various events I was able to pinpoint where I had made the error. Thanks to Jon and Erik! rating++

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!