Sign in to follow this  

Subtile bug? (Evaluating variables gives unexpected rezult) *Solved*

This topic is 4355 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 a class function that evaluates whether a interface button is being pressed or not. The function seems to work wright with almoust all buttons (and we have 30+ buttons) except a couple of them that won't get pressed. I've plugged in some helper code to figure out what's causing the problems and I got some puzzling rezults. Bellow is the function code and the log output:
HRESULT SubMenuIClass::Update(MouseBuff MsDevice)
{
   if (this->ID == 700)
   {
      Log("!!!!!New update for GShapes submenu \n ");
   }

   if (this->ID == 700)
   {
      if ( ( ( (MsDevice.X > SubmenuIButt[0].LeftEdge) && (MsDevice.Y > SubmenuIButt[0].UpperEdge) ) &&
             ( (MsDevice.X < SubmenuIButt[0].RightEdge) && (MsDevice.Y < SubmenuIButt[0].LowerEdge) ) ) && 
           (MsDevice.LBDown) )
      {
         Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! \n ");
      }
   }
	
//-------------------------	

   for (int ButtonNumber =0; ButtonNumber<NrOfButtons; ButtonNumber++)
   {
      if (!SubmenuIButt[ButtonNumber].NoDown)
      {
          if (this->ID == 700)
             Log("Ready to evaluate Interface button state \n ");

          if ( ( ( (MsDevice.X > SubmenuIButt[ButtonNumber].LeftEdge) && (MsDevice.Y > SubmenuIButt[ButtonNumber].UpperEdge) ) &&
                 ( (MsDevice.X < SubmenuIButt[ButtonNumber].RightEdge) && (MsDevice.Y < SubmenuIButt[ButtonNumber].LowerEdge) ) ) &&
               (MsDevice.LBDown) )
          {   
              if (this->ID == 700)
                 Log("This message never gets printed");

              SubmenuIButt[ButtonNumber].PlaySound();  // Play the buttons sound when the button is being pressed
			
              SubmenuIButt[ButtonNumber].Down = 1;   //  Change the button state to Down;


The SubmenuIButt[x] buttons never get pressed. The output from my log file looks like this:
 !!!!!New update for GShapes submenu 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 !!!!!New update for GShapes submenu 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 
 !!!!!New update for GShapes submenu 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! 
 Ready to evaluate Interface button state 
 Ready to evaluate Interface button state 


Our game has some unsolved memory leaks. Is it posible these memory leaks might be causing the problem? Thanks for any input.
Edit by Fruny - code reformated for readability [Edited by - Calin on January 11, 2006 11:26:39 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
Our game has some unsolved memory leaks. Is it posible these memory leaks might be causing the problem?


Unlikely.

If I were you, I would print out the values of the variables involved in the condition.

Share this post


Link to post
Share on other sites
Seconded. The results you get are perfectly possible, baring any additional constraints in code you haven't posted. Consider the following (code reposted with line numbers):
/* 01 */ HRESULT SubMenuIClass::Update(MouseBuff MsDevice)
/* 02 */ {
/* 03 */ if (this->ID == 700)
/* 04 */ {
/* 05 */ Log("!!!!!New update for GShapes submenu \n ");
/* 06 */ }
/* 07 */
/* 08 */ if (this->ID == 700)
/* 09 */ {
/* 10 */ if ( ( ( (MsDevice.X > SubmenuIButt[0].LeftEdge) && (MsDevice.Y > SubmenuIButt[0].UpperEdge) ) &&
/* 11 */ ( (MsDevice.X < SubmenuIButt[0].RightEdge) && (MsDevice.Y < SubmenuIButt[0].LowerEdge) ) ) &&
/* 12 */ (MsDevice.LBDown) )
/* 13 */ {
/* 14 */ Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! \n ");
/* 15 */ }
/* 16 */ }
/* 17 */
/* 18 */ //-------------------------
/* 19 */
/* 20 */ for (int ButtonNumber =0; ButtonNumber<NrOfButtons; ButtonNumber++)
/* 21 */ {
/* 22 */ if (!SubmenuIButt[ButtonNumber].NoDown)
/* 23 */ {
/* 24 */ if (this->ID == 700)
/* 25 */ Log("Ready to evaluate Interface button state \n ");
/* 26 */
/* 27 */ if ( ( ( (MsDevice.X > SubmenuIButt[ButtonNumber].LeftEdge) && (MsDevice.Y > SubmenuIButt[ButtonNumber].UpperEdge) ) &&
/* 28 */ ( (MsDevice.X < SubmenuIButt[ButtonNumber].RightEdge) && (MsDevice.Y < SubmenuIButt[ButtonNumber].LowerEdge) ) ) &&
/* 29 */ (MsDevice.LBDown) )
/* 30 */ {
/* 31 */ if (this->ID == 700)
/* 32 */ Log("This message never gets printed");
/* 33 */
/* 34 */ SubmenuIButt[ButtonNumber].PlaySound(); // Play the buttons sound when the button is being pressed
/* 35 */
/* 36 */ SubmenuIButt[ButtonNumber].Down = 1; // Change the button state to Down;

Assume that:
NrOfButtons == 11
SubmenuIButt[0].NoDown == true
SubmentIButt[/* 1..10 */] == false
MsDevice.X > SubmenuIButt[0].LeftEdge == true
MsDevice.X < SubmenuIButt[0].RightEdge == true
MsDevice.Y > SubmenuIButt[0].UpperEdge == true
MsDevice.Y < SubmenuIButt[0].LowerEdge == true
(MsDevice.X > SubmenuIButt[/* 1..10 */].LeftEdge &&
MsDevice.X < SubmenuIButt[/* 1..10 */].RightEdge &&
MsDevice.Y > SubmenuIButt[/* 1..10 */].UpperEdge &&
MsDevice.Y < SubmenuIButt[/* 1..10 */].LowerEdge) == false
MsDevice.LBDown == true
this->ID == 700

Now we call SubMenuIClass::Update. The conditional on line 3 is true so we print "!!!!!New update for GShapes submenu \n ". The conditionals on line 8 and lines 10-12 are also true, so we print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Menu button should go down now!!!! \n ". Now we start looping for the first iteration ButtonNumber is 0. The conditional on line 22 is false and so we continue to the next iteration of the loop. For all remaining iterations (ButtonNumber = 1..10) the conditionals on lines 22 and 24 are true, so we print "Ready to evaluate Interface button state \n " once on each of the ten iterations. The conditional on lines 27-29 on the otherhand is always false, so we never hit the conditional on line 31 and therefore never print "This message never gets printed".

Enigma

Share this post


Link to post
Share on other sites
You are both wright. The line 'if (!SubmenuIButt[ButtonNumber].NoDown)' evaluated false for the first 6 buttons. Thanks for helping me out solving this.

Share this post


Link to post
Share on other sites

This topic is 4355 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this