mnalis / ironseed_fpc

Iron Seed is a science-fiction DOS game from 1994, which was both developed and published by Channel 7. Gameplay is real-time, featuring trading, diplomacy, and strategy. This version has been changed to make it possible to compile it with the freepascal compiler under Linux.
GNU General Public License v3.0
17 stars 0 forks source link

sometimes the game fails to start due to race condition somewhere? #25

Closed mnalis closed 4 years ago

mnalis commented 4 years ago

[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

mnalis commented 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
mnalis commented 4 years ago

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

mnalis commented 4 years ago

When using just SDL, without OpenGL, it does not seem to fail (but without OpenGL we lose resize / full screen capability)

mnalis commented 4 years ago

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
mnalis commented 4 years ago

commenting out resizeWindow and/or glGenTextures in video_output() does not help to get rid of xcb_xlib_threads_sequence_lost.

mnalis commented 4 years ago

It turns out threads are HARD. Few more obvious things:

mnalis commented 4 years ago

however, 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...

mnalis commented 4 years ago

This will probably be need to fixed properly... Few resources:

Tutorials

mnalis commented 4 years ago

Current workflow is:

INITIALIZATION (THREAD 0)

main.pas -> starter.pas -> data.pas MAIN:

CALLBACKS

video_output (THREAD 1)

handle_keys (THREAD 2)

mnalis commented 4 years ago

Simplified current state:

mnalis commented 4 years ago

What needs to change: