Closed mnalis closed 4 years ago
Also, sometimes fails with:
% make build && ./main /playseed 3; echo $?
make: Nothing to be done for 'build'.
main: ../../src/xcb_io.c:239: poll_for_event: Assertion `dpy->xcb->event_owner == XlibOwnsEventQueue && !dpy->xcb->event_waiter' failed.
zsh: abort ./main /playseed 3
134
adding if idletime=10 then quit:=true;
in journey.pas
just before until quit
in mainloop()
, and running from shell with:
reset; (date; make build; failed=0; for c in `seq 1 100`; do
./main /playseed 3; ret=$?; [ $ret -ne 4 ] && let failed=failed+1;echo "test $c returns $ret" ; done;
echo "failed=$failed") | ts| tee -a fail_log.txt
indicates in fails in about 3%
of the cases when using OpenGL
When using just SDL, without OpenGL, it does not seem to fail (but without OpenGL we lose resize / full screen capability)
marked several variables used in multiple threads as volatile
drops the failure rate to 2/200
:
one is regular:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
main: ../../src/xcb_io.c:263: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aug 03 14:38:42 test 72 returns 134
but other is new:
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 92 requests (91 known processed) with 2 events remaining.
An unhandled exception occurred at $00007F8AF1FE539A:
EAccessViolation: Access violation
Aug 03 14:38:08 test 46 returns 1
commenting out resizeWindow
and/or glGenTextures
in video_output() does not help to get rid of xcb_xlib_threads_sequence_lost
.
It turns out threads are HARD. Few more obvious things:
video_output
, handle_keys
). It is buggy. volatile
might help in simplest cases, but we really need memory barriers, for example see thishowever, increasing SDL_Delay(20)
to SDL_Delay(50)
in c_utils.c
makes the problem go away on my machine, so I'll let it rest instead of rewriting graphic/audio/keyboard low-level implementation...
This will probably be need to fixed properly... Few resources:
"Can I call SDL video functions from multiple threads?" No, most graphics back ends are not thread-safe, so you should only call SDL video functions from the main thread of your application.
https://wiki.libsdl.org/CategoryThread "You should not expect to be able to create a window, render, or receive events on any thread other than the main one"
1 Input 2 Update Logic 3 Render 4 Goto 1"
SDL 1.2 threading docs: "In general, you must be very aware of concurrency and data integrity issues when writing multi-threaded programs. Some good guidelines include:
very good SDL forum thread about threading issues in X
Current workflow is:
main.pas -> starter.pas -> data.pas MAIN:
video_output
, NULL) // new thread: 1handle_keys
, NULL) // new thread: 2Simplified current state:
PASCAL (thread 0)
musicDone
)video_output
and handle_keys
video_output (thread 1) almost-infinite loop
handle_keys (thread 2) almost-infinite loop
What needs to change:
handle_keys
and video_output
into one threadhandle_keys_and_video_output
thread will detect and initialize Mix*, SDL_Init, ... ext.txt
for list), and how many params they may contain...handle_keys_and_video_output
thread there is no \b(SDL|gl|Su?lock)
function calls
[xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. main: ../../src/xcb_io.c:263: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. zsh: abort ./main /playseed