We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3383 - event queue
Summary: event queue
Status: WAITING
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.4
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-05 03:10 UTC by sage
Modified: 2017-11-09 16:42 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sage 2016-07-05 03:10:31 UTC
1,in the main thread process events, get the mouse motion event data, look like thats 
local position is  666 --- 494 and time is 44547
local position is  619 --- 506 and time is 44616
local position is  601 --- 514 and time is 44667
local position is  581 --- 524 and time is 44734
local position is  565 --- 532 and time is 44784
local position is  544 --- 538 and time is 44834
local position is  527 --- 545 and time is 44882
local position is  502 --- 557 and time is 44954
local position is  468 --- 570 and time is 45005
local position is  437 --- 584 and time is 45067
local position is  416 --- 594 and time is 45124
local position is  391 --- 607 and time is 45187
local position is  373 --- 616 and time is 45243
local position is  355 --- 627 and time is 45302

local position is  663 --- 495 and time is 45418 (that one is wrong, it should be in the second)

local position is  352 --- 627 and time is 45699

2,i have a threadpool ,the thread of threadpool will use SDL_PushEvent().

3,if i use SDL_AddEventWatch set a callback to process events, the event queue will be ok.
Comment 1 Sam Lantinga 2017-08-12 01:16:02 UTC
Can you attach your test program so we can replicate this here?

Thanks!
Comment 2 Sylvain 2017-11-09 16:42:22 UTC
Just looking at the bug report, it seems because SDL_PushEvent() is doing:

First:
 getting the timestamp: event->common.timestamp = SDL_GetTicks();
Then:
 locking the queue and pushing the event.

If there is several threads pushing events, the issue can occur. For instance:

thread-1: getting the timestamp1
thread-2: getting the timestamp2
thread-2: pushing the event with timestamp2
thread-1: pushing the event with timestamp1


several solutions: 
- put the timestamp once you have locked the queue, but it may be older then.
or
- insert in the middle of queue. But user might have already read the queueu ...
or
- discard the event ...
or
- implement double timestamp: native and when pushing. see bug 2011
or
- just don't expect event be timestamp order in that case ...