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

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

0 Members and 1 Guest are viewing this topic.

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Something strange... (Mouse click)
« Reply #15 on: July 09, 2008, 09:47:44 pm »
I tried it under linux (wine and linux native build) and everything seemed to work.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #16 on: July 09, 2008, 10:07:04 pm »
Ok thanks for trying under linux.

The weirdest of all is that any button but the left one seem to works.

If I was to rewrite the code, any ideas how? In my honest opinion it's written pretty straight forward as it is.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Something strange... (Mouse click)
« Reply #17 on: July 09, 2008, 10:21:21 pm »
I noticed the fast change when left button is clicked sometime. I thought it was something with window focus, it seems not.
I'm keeping up with it...
Mindiell
----

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Something strange... (Mouse click)
« Reply #18 on: July 09, 2008, 10:35:43 pm »
Tried on my home computer : no problem... It seems I can't reproduce it, all is running well !

I use the same C:B version here and at the office, the only difference I can see now is that we use XP at the office, and I'm still using W2K at home.

When speaking about Window focus, maybe XP is doing something that w2k is not ?

So it's maybe not SFML...
Mindiell
----

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #19 on: July 09, 2008, 11:19:59 pm »
Hmm ok. All 3 computers I've tried running the game on uses Win XP Pro, so it might be XP's fault.

As you have been saying Mindiell, it looks like there is something going on with window focus.

I logged all event types coming when I do a left button press.

On success the following event types were generated:
8 - MouseButtonPressed
9 - MouseButtonReleased

On failure the following event types were generated:
2 - LostFocus
3 - GainedFocus
9 - MouseButtonReleased (that's why MouseButtonReleased works without any problems)

The questions are; Where does the MouseButtonPressed event go and why does the window loose focus (only the left button makes the window lose focus)?

EDIT: I've also noticed that the window seems to lose focus randomly for seemingly no reason. At least we know the hour-glass appears because of the window losing focus.

I've tried it myself under linux and everything seem to work.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Something strange... (Mouse click)
« Reply #20 on: July 10, 2008, 10:53:41 am »
I'll test it on another computer with XP Home to see if the same thing happens. I'll let you know...
Mindiell
----

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #21 on: July 10, 2008, 12:09:55 pm »
I've removed most of the code in the game-loop and added a short piece of code that will decrease a counter for about the same amount of time as it took for the wheels to stop spinning:

Code: [Select]
while(1)
{
sf::Event eEvent;
while(App.GetEvent(eEvent))
{
if(eEvent.Type != 10)
std::cout << eEvent.Type << std::endl;

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 = App.GetInput().GetMouseX();
int mouseY = App.GetInput().GetMouseY();
int hit = -1;

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

//if a button was pressed, act accordingly
switch(hit)
{
case 0: exit(EXIT_SUCCESS);

case 2: if(!bIsSpinning) //if wheels are not spinning, start spinning
{
for(int i = 0; i < signed(v_iWheelsLeftToSpin.size()); i++)

spin += sf::Randomizer::Random(5, 19);


spin += 10;

bIsSpinning = true; //the wheels are spinning
}
break;
}
}
}

                                //New code
if(spin <= 0)
bIsSpinning = false;
else
{
offset = (offset + 1) % 96;

if(offset == 0)
spin -= 2;
}
                                //New code end

std::stringstream ss2;
ss2 << spin;
sf::String str(ss2.str());
str.SetPosition(10.f, 10.f);
App.Draw(str);

App.Display();
}


Even this short code fails to work. Does the time waiting for the wheels to stop/counter to reach 0 (this example) cause the window to lose focus? Seems weird to me.

Is visual studio forcing the window to have focus as the problem doesn't appear debugging it?

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Something strange... (Mouse click)
« Reply #22 on: July 10, 2008, 12:27:53 pm »
Quote from: "dabo"
Is visual studio forcing the window to have focus as the problem doesn't appear debugging it?
I have the problem even if under my EDI (C::B, I d'ont use VS).
Mindiell
----

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #23 on: July 10, 2008, 12:43:54 pm »
Quote from: "Mindiell"
Quote from: "dabo"
Is visual studio forcing the window to have focus as the problem doesn't appear debugging it?
I have the problem even if under my EDI (C::B, I d'ont use VS).


Yea I've tried code::blocks myself, and the problem always exists. That's why I was wondering if visual studio is forcing focus on the window while debugging while code::block doesn't.

...I tried speeding up the wheels, I changed:

Code: [Select]
1000.f * App.GetFrameTime();

to

Code: [Select]
2000.f * App.GetFrameTime();

the problem seems gone as long as I click to spin the wheels again right after they have stopped, if I wait for a while the problem is there again. It looks like if you just sit there and do nothing, the window seems to lose focus after a while. That can't be right can it?

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #24 on: July 10, 2008, 12:55:45 pm »
I think I have found something!

When creating the renderWindow if I use the style Fullscreen or None it seems to work! Using the other styles don't work. Could you guys try that as well and see if it works for you?

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #25 on: July 10, 2008, 11:08:33 pm »
I confirmed it doesn't happen with style set to None or Fullscreen.
I have also confirmed it never happens when a debugger is attached.
You can attach a debugger while the app is running (even after the problem occurs) and it will not occur.
It's very odd.
I feel like this is maybe a windows quirk. Maybe windows is doing something different behind the scenes when a debugger is present.
I just don't know!

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #26 on: July 10, 2008, 11:13:12 pm »
I have no problem using Style::None in the final version of the game but it sure is strange. Thanks for confirming it.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #27 on: August 01, 2008, 03:12:36 am »
Sorry to revive a slightly old thread but...

I've actually experienced this in my game recently.
In debug mode I've had it happen a few times.
In release mode I've had it happen at least once.
Just putting that out there.
I feel like this has to be a bug in SFML.
I mean, you don't see any other windows games/apps having this problem.
Anyways, it's been pretty rare so I'm not too concerned about it.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Something strange... (Mouse click)
« Reply #28 on: August 01, 2008, 11:48:24 am »
It would be really interesting to know what causes it.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Something strange... (Mouse click)
« Reply #29 on: August 01, 2008, 03:20:16 pm »
Quote from: "dabo"
It would be really interesting to know what causes it.

Indeed.

 

anything