Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_WaitEvent() polls #222

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

SDL_WaitEvent() polls #222

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

@SDLBugzilla SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 1.2.7
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2006-09-06 14:04:14 +0000, Eero Tamminen wrote:

SDL version:

  • I've got SDL version v1.2.7, but I've understood that the bug
    is also in the v1.2.8

How to repeat:

  • Run a program that sits in a loop waiting SDL_WaitEvent() call to end
  • Attach to the process with Gdb to see that the SDL_WaitEvent() function
    call is really blocking the program while SDL doesn't receive events
  • continue the process and attach strace to it:
    strace -tt -p

Expected outcome:

  • SDL sits in a select() until it receives an event

Actual outcome:

20:03:56.145652 select(4, [3], NULL, NULL, {0, 0}) = 0 (Timeout)
20:03:56.145972 select(0, NULL, NULL, NULL, {0, 10000}) = 0 (Timeout)
20:03:56.156151 select(4, [3], NULL, NULL, {0, 0}) = 0 (Timeout)
20:03:56.156423 select(0, NULL, NULL, NULL, {0, 10000}) = 0 (Timeout)
...

SDL polls between these two select calls constantly several times a second.

Effect of the bug:

  • On a mobile device the CPU cannot sleep because the process isn't idle
    and SDL drains the device battery (while the SDL application would be
    otherwise idle)

On a mobile device this kind of bugs are "must fix" things...

On 2006-10-28 21:33:00 +0000, Ryan C. Gordon wrote:

We'd need to change the video backends to optionally block in PumpEvents() without returning immediately. This gets a little stickier when you want joystick events, too, though, since they go through a different path in both SDL and most OSes. I'll look at the former here.

--ryan.

On 2006-10-28 23:32:01 +0000, Ryan C. Gordon wrote:

Created attachment 176
Block without polling in SDL_WaitEvent() patch.

Here's a patch that removes polling from SDL_WaitEvent() when possible, including support in a surprisingly large percentage of the platform-specific backends. All the Unixy things that fall into a select() call (including X11 and fbcon) are supported.

Some notes:

  • Existing behaviour remains (poll,sleep,poll,sleep) for backends that can't supply a non-polling mechanism. An internal interface changed, but besides updating the function signatures, code can just do what it did before and it gets handled properly.
  • If there's a joystick detected, polling is used for everything (since we can't block in two different places). I don't have a good solution for this. At the app level, you can either unplug all your joysticks, or call SDL_Init() without SDL_INIT_JOYSTICK (or SDL_INIT_EVERYTHING). Eventually we may change this to at least only resort to polling when a stick is opened as opposed to detected.
  • Enabling key repeat turns on polling while a key is pressed down (can't block in PumpEvents if this is to trigger reliably). It's off by default.
  • Don't use SDL_INIT_EVENTTHREAD. You probably aren't anyhow. That still polls in all cases, at least for now, since I haven't checked all the corner cases.

Apply this patch to Subversion.

--ryan.

On 2006-10-28 23:34:20 +0000, Ryan C. Gordon wrote:

Tossing bug to Sam for approval on the patch.

--ryan.

On 2007-02-15 05:51:46 +0000, Ryan C. Gordon wrote:

After consideration, I'm going to flag this bug as WONTFIX, since I don't think such a big change with this many caveats should be made to the 1.2 branch at this point, but we can still point people to this bug if they want to use the patch in a custom SDL on an embedded device.

Sam, please feel free to reopen the bug (and apply the patch to Subversion) if you disagree.

--ryan.

On 2008-03-02 10:36:57 +0000, Eero Tamminen wrote:

(In reply to comment # 4)

After consideration, I'm going to flag this bug as WONTFIX, since
I don't think such a big change with this many caveats should be made
to the 1.2 branch at this point,

Is this going to be considered for some later SDL version?

but we can still point people to this bug if they want to use the
patch in a custom SDL on an embedded device.

Even people using laptops and desktop machines can be nowadays be
interested about something like this...

On 2010-05-10 10:23:33 +0000, Eero Tamminen wrote:

(In reply to comment # 5)

After consideration, I'm going to flag this bug as WONTFIX, since
I don't think such a big change with this many caveats should be made
to the 1.2 branch at this point,

Is this going to be considered for some later SDL version?

but we can still point people to this bug if they want to use the
patch in a custom SDL on an embedded device.

Even people using laptops and desktop machines can be nowadays be
interested about something like this...

Ping... It's three years from WONTFIXing this for 1.2.7 and two years from my above comment. This isn't fixed e.g. in current SDL v1.2.13 in Debian. Is it ever going to be?

On 2011-12-30 00:31:42 +0000, Ryan C. Gordon wrote:

(In reply to comment # 6)

Ping... It's three years from WONTFIXing this for 1.2.7 and two years from my
above comment. This isn't fixed e.g. in current SDL v1.2.13 in Debian. Is it
ever going to be?

No, my WONTFIX stands. Debian (etc) can feel free to ship with the patch attached to this bug, but we've decided not to make this change for SDL 1.2.

--ryan.

On 2021-01-10 03:30:35 +0000, wrote:

Created attachment 4649
ryan's patch for 1.2.10

On 2021-01-10 03:31:22 +0000, wrote:

Created attachment 4650
ryan's patch for 1.2.11

On 2021-01-10 03:31:52 +0000, wrote:

Created attachment 4651
ryan's patch for 1.2.12

On 2021-01-10 03:32:29 +0000, wrote:

Created attachment 4652
ryan's patch for 1.2.13

On 2021-01-10 03:33:05 +0000, wrote:

Created attachment 4653
ryan's patch for 1.2.14

On 2021-01-10 03:33:38 +0000, wrote:

Created attachment 4654
ryan's patch for 1.2.15

On 2021-01-10 03:36:11 +0000, wrote:

i forward-ported ryan's patch to all SDL 1.2 releases past the patch creation date.

however since 1.2.12 2 platforms have been removed and 2 (or more added), those are not covered.

from 1.2.12 release notes:

Support for AmigaOS has been removed from the main SDL code.
Support for Nokia 9210 "EPOC" driver has been removed from the main SDL code.
Unofficial support for the S60/SymbianOS platform has been added.
Unofficial support for the Nintendo DS platform has been added.

i hope this helps when porting this crucial feature to SDL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant