Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Something strange... (Mouse click)  (Read 15086 times)

0 Members and 1 Guest are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« on: July 06, 2008, 01:45:08 pm »
There seems to be something strange going on when it comed to reacting to mouse clicks. I have some buttons (images, no gui) where the user can click and everything works until the 3rd click (99.9% of the time). After that you randomly have to click the button once/twice before anything happens. If I run my game with visual studios 2008 pro (start debugging) this problem never occurs but if I close visual studios and double click the executable it does. Today I discovered that the problem occures if I don't move the mouse at all during the first 3 clicks, If I move it before I click the 3rd time it works.  :?

I have tried it on 3 computers, my laptop gets the behavior described above and the other two get the problem as well, but not necessarily on the 3rd click.

I have designed my game in two completely different ways (exept for the event-loop) but the problem shows up for both. I have tried events and inputs for mouse clicks but both have the same problem. I'm linking with the static libraries.

This is the event-loop:
Code: [Select]
sf::Event eEvent;
while(renderer::getInstance()->getRenderWindow()->GetEvent(eEvent))
{
if(eEvent.Type == sf::Event::KeyPressed && eEvent.Key.Code == sf::Key::Escape)
exit(EXIT_SUCCESS);

else if(eEvent.Type == sf::Event::MouseButtonPressed && eEvent.MouseButton.Button == sf::Mouse::Left)
{
int mouseX = renderer::getInstance()->getRenderWindow()->GetInput().GetMouseX();
int mouseY = renderer::getInstance()->getRenderWindow()->GetInput().GetMouseY();
int hit = -1;

for(int i = 0; i < 5; i++)
{
if(v_iClickables[i].Contains(mouseX, mouseY)) //check clickable regions (sf::IntRect)
{
hit = i;
break;
}
}

         //if a button was pressed, act accordingly
if(hit == 0)
exit(EXIT_SUCCESS);
else if(hit == 1)
; //to be implemented
else if(hit == 2)
{
if(!bIsSpinning) //if wheels are not spinning, start spinning
{
for(int i = 0; i < signed(v_iWheelsLeftToSpin.size()); i++)
v_iWheelsLeftToSpin[i] = sf::Randomizer::Random(5, 19);

v_iWheelsLeftToSpin[0] += 10;

bIsSpinning = true;
}
}
else if(hit == 3)
; //to be implemented
else if(hit == 4)
; //to be implemented
}
}


I should be able to put together an example if you want to see the problem in action. I have no idea why the problem only occurs if you run the executable and not when you are debugging it with visual studio :?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Something strange... (Mouse click)
« Reply #1 on: July 06, 2008, 01:54:32 pm »
Sounds weird :|

Quote
I should be able to put together an example if you want to see the problem in action

Yep, it would help a lot as I have no clue.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #2 on: July 06, 2008, 02:15:10 pm »
Ok here it is, use the SPIN-button in-game.

Click BAIL-button / esc-key to quit

Download link

Note, it might not happen the 3rd time you click, it's been different with the 3 computers I have tried it on.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Something strange... (Mouse click)
« Reply #3 on: July 06, 2008, 03:09:50 pm »
I got the same issue with your game, however I couldn't reproduce it in a simple application.

So what I suggest is that you try to reduce your code to a minimal and complete app which reproduces the problem.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #4 on: July 06, 2008, 03:25:55 pm »
Ok, I will try that.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #5 on: July 06, 2008, 05:31:12 pm »
I have managed to remove a lot of code and the problem is still there. There isen't much code now so I would be happy if someone could take a look at it, I might be using sfml wrong (noone else has this problem) or it's my game logic (which I will look over again later). I have stared at this code for a very long time now and I think I've gone blind  :)

Use the same download link as before for the updated version. I have removed the interface in this version but the buttons are at the same postions as before still clickable.

Note: Build a project with the code and see for yourself how well it works as long as you run it from visual studio.

I have also noticed that when the problem occurs the cursor-arrow changes to an hour-glass very quickly...

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #6 on: July 06, 2008, 07:10:57 pm »
It does seem to have a small problem.

Just glancing through the code, I'd suggest you clean it up.
That may help you find the problem here.
Instead of all these if statements, use a switch.
And in your execute() loop, you might want to use statics as an optimization since it's called a lot.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #7 on: July 06, 2008, 09:39:28 pm »
After removing the code that calculates the new positions for the sprites and draw them the problem is gone. I don't understand how that code can mess up event handling, and only when I'm not debugging it in visual studio (which means debugging the game for the error is useless)  :? . I don't know how to write the code I removed differently, I mean it has nothing to do with events and still I get this damn behavior.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #8 on: July 06, 2008, 11:40:14 pm »
If it wasn't weird enough already here comes more.

I have gotten two versions to work (only tested on my laptop, gonna try the other once tomorrow)

1. Using any mouse button but the left one on button pressed.

2. Using the left mouse button on button released.

 :?  :?  :?

Pretty much everything but the way I want works it looks like, but I guess I could go with button released instead of pressed. But I really want to know why left pressed doesn't work!

I have uploaded another file, try it and see if it works on your computer as well. There are two executables this time, each showing one of the scenarios above. Notice though how the hour-glass shows up for a short period of time only when pressing the left mouse button, never for the others. Nothing make sense right now, so it's probably something obvious :)

Download link

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #9 on: July 09, 2008, 12:38:31 pm »
Has anyone done some more digging into this? I myself can't let it go, nothing makes sense, that's probably why I don't have a clue how to fix this. I'm considering rewriting the entire code.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Something strange... (Mouse click)
« Reply #10 on: July 09, 2008, 12:48:31 pm »
Sorry, same for me (totally weird and no clue about what's happening) :(

And I can't even reproduce it in a simple code, except yours.
Laurent Gomila - SFML developer

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #11 on: July 09, 2008, 03:31:50 pm »
Yeah this really is weird.
I nearly rewrote the whole thing in a little framework.
If run under the debugger, it's all fine.
But when you run it alone, that weird thing happens.

I suggest you try to rewrite it in a different way.
This must be some weird bug in MSVC/CRT or SFML. Who knows.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Something strange... (Mouse click)
« Reply #12 on: July 09, 2008, 05:17:04 pm »
I got this when logging events :
Quote
Left Click detected !
hit = 2
hit on 2
Start spinning
37.9295
Stop spinning
45.8926
45.8932
45.8939
45.9785
51.8179
51.8191
51.8198
51.8823
55.9586
59.2977
Left Click detected !
hit = 2
hit on 2
Start spinning
59.4034

I pressed LeftButton 4 times, and get only two real events. At 45 and 51, it didn't detect my click

And finally I found !
Quote
Left Click detected !
hit = 2
hit on 2
Start spinning
Button released !
Stop spinning
Button released !
Button released !
Button released !
Left Click detected !
hit = 2
hit on 2
Start spinning
Button released !

Sometime, the buttonpressed event seems to be erased by the buttonreleased event...

For information, I'm not clicking 3 times, but I'm just waiting for a few seconds instead...
Mindiell
----

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #13 on: July 09, 2008, 09:21:56 pm »
Mindiell: So it has something to do with sfml?

I mean there's no way my code to spin and draw the wheels can mess up the event's right? how could it? Have you also noticed how the cursor switches to the hour-glass quickly sometimes only when pressing the left mouse button? never with any other button.

I builded the game with Code::Blocks and got the same behaviour.

Thanks everyone for trying.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #14 on: July 09, 2008, 09:33:05 pm »
Quote from: "dabo"
Mindiell: So it has something to do with sfml?

I mean there's no way my code to spin and draw the wheels can mess up the event's right? how could it? Have you also noticed how the cursor switches to the hour-glass quickly sometimes only when pressing the left mouse button? never with any other button.

I builded the game with Code::Blocks and got the same behaviour.

Thanks everyone for trying.

It seems like it has something to do with SFML to me.

I don't know how your code could screw with events.
And yes, I noticed the cursor changes to an hourglass for some reason.

I do wonder if this problem exists under linux as well.

 

anything