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

Author Topic: false trigger of mouse event  (Read 2892 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
false trigger of mouse event
« on: November 11, 2015, 07:04:35 pm »
I'm using mouse button in my game to capture control of some entity. so, while mouse button is pressed I can move entity. And it works well.
But I catch some weird bug, sometimes when I hold mouse button pressed, it rases several pressed/released events, so I lose control on desired entity. It happens rare, so I cannot catch it under debugger. I added logging and all what I can see that there are some false triggered pressed/release event. Is there any way to prevent fire of unexpected pressed/released event when mouse button state actually didn't changed and it is still pressed?
« Last Edit: November 12, 2015, 08:29:58 pm by mkalex777 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: false trigger of mouse event
« Reply #1 on: November 11, 2015, 08:29:04 pm »
Are you creating a new sf::Event on each frame?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: false trigger of mouse event
« Reply #2 on: November 11, 2015, 09:08:39 pm »
We can't help you unless you provide a complete and minimal example that reproduces the problem.

Also, make sure that you're not mixing different versions of SFML/CSFML/SFML.Net.
Laurent Gomila - SFML developer

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: false trigger of mouse event
« Reply #3 on: November 11, 2015, 09:16:20 pm »
It's not easy to reproduce it, because it may works without such bug for a long time. But sometimes it starts to happen. Probably it appears when there are a lot of render objects on the screen ( rectangle & circle shapes, text), but I'm not sure that it's related. Also I've seen that when I pressing some buttons on the keyboard (space for example) it happens more frequently. Actually it's float bug, so I can't catch it in the debugger.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: false trigger of mouse event
« Reply #4 on: November 11, 2015, 09:23:28 pm »
I'm sure you can understand that we have no chance of helping you with such a description ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: false trigger of mouse event
« Reply #5 on: November 11, 2015, 11:48:26 pm »
You may also want to do a quick check and make sure it isn't a hardware problem with your mouse. Sometimes when mice get worn out the buttons can start to "bounce". Do you have another mouse you can try to reproduce the problem with?

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: false trigger of mouse event
« Reply #6 on: November 12, 2015, 05:50:12 pm »
You may also want to do a quick check and make sure it isn't a hardware problem with your mouse. Sometimes when mice get worn out the buttons can start to "bounce". Do you have another mouse you can try to reproduce the problem with?

I implemented some check and it seems that it's SFML issue. I added check of actual mouse state from WinAPI. And sometimes SFML report about released key when WinAPI reports that key is still pressed.

Here is an example:
        private static class NativeMethods
        {
            [System.Runtime.InteropServices.DllImport("user32")]
            [System.Security.SuppressUnmanagedCodeSecurity]
            public static extern short GetAsyncKeyState(int vKey);

            public const int VK_LBUTTON = 1;
            public const int VK_RBUTTON = 2;
            public const int VK_MBUTTON = 4;
        }

        private void Window_OnMouseButtonReleased(object sender, MouseButtonEventArgs e)
        {
            if (e.Button == Mouse.Button.Left &&
                NativeMethods.GetAsyncKeyState(NativeMethods.VK_LBUTTON)!=0)
            {
                Logger.Warn("Window_OnMouseButtonReleased: false trigger");
                return;
            }
       }
 

result:
[ WARN] Window_OnMouseButtonReleased: false trigger
 

There is need for a long time testing to catch it, because it didn't trigger false event just after app startup.

UPDATE: it seems that I found the reason, I used Mouse.GetPosition in the render loop. I assume that this call may disrupt some internal SFML state and tried to remove it.
I replaced it with position stored in the local variable and set in the MouseMooved event. And yes! It seems that this weird bug disappears.

UPDATE2: no, it still reproduced. Needs to check my mouse to make sure that it's not hardware issue
« Last Edit: November 12, 2015, 08:30:45 pm by mkalex777 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: false trigger of mouse event
« Reply #7 on: November 12, 2015, 08:32:17 pm »
Quote
Need some time to make sure that it won't appears again.
You can also make sure that it always happens with the old code. Now that you know what triggers it, maybe it will happen more frequently in a code that does just that.

Before labeling this as a bug, we need to make sure that it doesn't happen only in your environment. We also need to check wether it's a bug in SFML.Net, CSFML or SFML.
Laurent Gomila - SFML developer