SDL mouse handling code is broken

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

SDL mouse handling code is broken

Post by Gutawer »

So I was writing a menu today and wanted to make it respond to right clicking and dragging, when I discovered that right clicking and dragging wasn't working for me as no Type_MouseMove event was getting fired. I've made sure that it works fine on Windows by asking Nash to run the code I was using:

Code: Select all

class Test : EventHandler {
    override void WorldTick() { isUiProcessor = true; requireMouse = true; }
    override bool UiProcess(UiEvent e)
    {
        if (e.type == UIEvent.Type_MouseMove)
        {
            Console.printf("%d", gametic);
        }
        return false;
    }
}
On either OS, moving the mouse around here prints the gametic continuously. On Windows, pressing right click does nothing to this and it carries on going, but on Linux, it stops printing the gametic immediately, so the event isn't being fired. I've looked into the code at src/i_input.cpp and after some googling and talking to Marisa Kirisame on Discord, the issue seems to be this sort of thing:

Code: Select all

	case SDL_MOUSEBUTTONDOWN:
	case SDL_MOUSEBUTTONUP:
	case SDL_MOUSEMOTION:
		if (!GUICapture || sev.button.button == 4 || sev.button.button == 5)
		{
SDL_Event is a union, so this is treating sev as if it's a Button event regardless of if it's actually a Motion event. This appears to basically be invoking undefined behaviour, and the exact same issue can be found at https://stackoverflow.com/questions/129 ... consistent.
I'd attempt to fix this myself but I tend to avoid SDL so have no significant experience working with it.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: SDL mouse handling code is broken

Post by Gutawer »

Just a heads up - I've decided to fix this myself. I'm heading to bed now but in the morning I'll finish fixing stuff up and get some people to test if my fixes work on their machines.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: SDL mouse handling code is broken

Post by _mental_ »

I have pushed the fix. Although, I tested it on macOS where SDL backend can behave differently from Linux. In any case, wrong event data were read, so an extra check is needed.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: SDL mouse handling code is broken

Post by Edward-san »

Actually, see here. The check is there, but the order of the checking was inverted.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: SDL mouse handling code is broken

Post by _mental_ »

I guess you forgot about else block. Anyway, please post code. It's not obvious how you propose to change it.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: SDL mouse handling code is broken

Post by Gutawer »

Thanks for taking a look, but I don't feel like this fix is really complete. There's a bunch of other bugs in this code such as the EV_GUI_BackButtonDown/Up and EV_GUI_FwdButtonDown/Up events never being fired and the button mappings for all of the extra mouse buttons (MOUSE4-8) being handled wrong. This is my proposed fix for all the issues: https://github.com/Gutawer/gzdoom/commi ... 9135e05dcb. Hopefully this should be tested by anyone who runs Linux/any other OS where the SDL backend can be used (my comment in the code reflects that hopefully this should have been done before merging).
There is one other issue which I'm not sure exactly how to fix, which is that the event handler requireMouse field is never actually checked in SDL, so event handlers will always get mouse events regardless of whether they want them.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: SDL mouse handling code is broken

Post by _mental_ »

Please do a PR, it's much easier to comment there.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: SDL mouse handling code is broken

Post by Gutawer »

_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: SDL mouse handling code is broken

Post by _mental_ »

I have posted a few comments in PR. I cannot run it at the moment, so I could get something wrong though.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: SDL mouse handling code is broken

Post by _mental_ »

Fixed in aa75f08.
Post Reply

Return to “Closed Bugs [GZDoom]”