.hgignore
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Oct 2016 04:54:43 -0700
changeset 10530 2a3f8bc23daa
parent 10303 b326f93e1bc5
child 11702 cf166abbde4a
permissions -rw-r--r--
Fixed bug 3328 - Race condition in Wayland_VideoInit

Robert Folland

When running this little test program with SDL2 on Wayland it often crashes in SDL_Init.

From a backtrace it is apparent that there is a race condition in creating a xkb_context_ref. Sometimes it is 0x0.

By moving the relevant lines higher up in Wayland_VideoInit (in SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302) this seems to get fixed.

I moved the call to WAYLAND_xkb_context_new() up to before the call to WAYLAND_wl_display_connect().

Here is the test program (just a loop of init and quit), and a backtrace from gdb:

#include <cstdio>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
int count = atoi(argv[1]);

for (int i = 0; i < count; i++) {
std::cout << "Init " << i << std::endl;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Couldn't initialize SDL: %s\n",
SDL_GetError());
return 1;
}
std::cout << "Quit" << std::endl;
SDL_Quit();
}
return 0;
}


Init 12
Quit
Init 13

Program received signal SIGSEGV, Segmentation fault.
xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
156 ctx->refcnt++;
(gdb) bt
#0 xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
#1 0x00007ffff5e1cd4c in xkb_keymap_new (ctx=0x0, format=XKB_KEYMAP_FORMAT_TEXT_V1, flags=flags@entry=XKB_KEYMAP_COMPILE_NO_FLAGS) at src/keymap-priv.c:65
#2 0x00007ffff5e1c6cc in xkb_keymap_new_from_buffer (ctx=<optimized out>,
buffer=0x7ffff7fd5000 "xkb_keymap {\nxkb_keycodes \"(unnamed)\" {\n\tminimum = 8;\n\tmaximum = 255;\n\t<ESC>", ' ' <repeats 16 times>, "= 9;\n\t<AE01>", ' ' <re
peats 15 times>, "= 10;\n\t<AE02>", ' ' <repeats 15 times>, "= 11;\n\t<AE03>", ' ' <repeats 15 times>, "= 12;\n\t<AE04>", ' ' <repeats 12 times>..., length=48090,
format=<optimized out>, flags=<optimized out>) at src/keymap.c:191
#3 0x00007ffff7b8ea4e in keyboard_handle_keymap (data=0x6169b0, keyboard=<optimized out>, format=<optimized out>, fd=5, size=48091)
at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandevents.c:269
#4 0x00007ffff64501f0 in ffi_call_unix64 () from /usr/lib/libffi.so.6
#5 0x00007ffff644fc58 in ffi_call () from /usr/lib/libffi.so.6
#6 0x00007ffff665be3e in wl_closure_invoke (closure=closure@entry=0x61f000, flags=flags@entry=1, target=<optimized out>, target@entry=0x616d20,
opcode=opcode@entry=0, data=<optimized out>) at src/connection.c:949
#7 0x00007ffff6658be0 in dispatch_event (display=<optimized out>, queue=<optimized out>) at src/wayland-client.c:1274
#8 0x00007ffff6659db4 in dispatch_queue (queue=0x617398, display=0x6172d0) at src/wayland-client.c:1420
#9 wl_display_dispatch_queue_pending (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1662
#10 0x00007ffff665a0cf in wl_display_roundtrip_queue (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1085
#11 0x00007ffff7b8faa0 in Wayland_VideoInit (_this=<optimized out>) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302
#12 0x00007ffff7b7aed6 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/SDL_video.c:513
#13 0x00007ffff7ae0ee7 in SDL_InitSubSystem_REAL (flags=16416) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/SDL.c:173
#14 0x0000000000400b24 in main (argc=2, argv=0x7fffffffebb8) at vplay-init.cpp:13
(gdb)
     1 syntax:glob
     2 aclocal.m4
     3 autom4te*
     4 config.cache
     5 config.log
     6 config.status
     7 Makefile
     8 sdl-config
     9 SDL2.spec
    10 build
    11 gen
    12 Build
    13 
    14 # for Xcode
    15 *.orig
    16 *.swp
    17 *.tmp
    18 *.rej
    19 *~
    20 *.o
    21 *.mode1*
    22 *.perspective*
    23 *.pbxuser
    24 (^|/)build($|/)
    25 .DS_Store
    26 xcuserdata
    27 *.xcworkspace
    28 
    29 # for Visual C++
    30 Debug
    31 Release
    32 *.user
    33 *.ncb
    34 *.suo
    35 *.sdf
    36 VisualC/tests/loopwave/sample.wav
    37 VisualC/tests/testautomation/CompareSurfaces0001_Reference.bmp
    38 VisualC/tests/testautomation/CompareSurfaces0001_TestOutput.bmp
    39 VisualC/tests/testgamecontroller/axis.bmp
    40 VisualC/tests/testgamecontroller/button.bmp
    41 VisualC/tests/testgamecontroller/controllermap.bmp
    42 VisualC/tests/testoverlay2/moose.dat
    43 VisualC/tests/testrendertarget/icon.bmp
    44 VisualC/tests/testrendertarget/sample.bmp
    45 VisualC/tests/testscale/icon.bmp
    46 VisualC/tests/testscale/sample.bmp
    47 VisualC/tests/testsprite2/icon.bmp
    48 VisualC/visualtest/icon.bmp
    49 VisualC/visualtest/testquit.actions
    50 VisualC/visualtest/testquit.config
    51 VisualC/visualtest/testquit.exe
    52 VisualC/visualtest/testquit.parameters
    53 VisualC/visualtest/testsprite2.exe
    54 VisualC/visualtest/testsprite2_sample.actions
    55 VisualC/visualtest/testsprite2_sample.config
    56 VisualC/visualtest/testsprite2_sample.parameters
    57 
    58 # for Android
    59 android-project/local.properties
    60 
    61 sdl.pc
    62 test/autom4te*
    63 test/config.cache
    64 test/config.log
    65 test/config.status
    66 test/Makefile
    67 test/SDL2.dll
    68 test/checkkeys
    69 test/controllermap
    70 test/loopwave
    71 test/loopwavequeue
    72 test/testatomic
    73 test/testaudiohotplug
    74 test/testaudioinfo
    75 test/testautomation
    76 test/testdraw2
    77 test/testdrawchessboard
    78 test/testdropfile
    79 test/testerror
    80 test/testfile
    81 test/testgamecontroller
    82 test/testgesture
    83 test/testgl2
    84 test/testgles
    85 test/testgles2
    86 test/testhaptic
    87 test/testhittesting
    88 test/testhotplug
    89 test/testiconv
    90 test/testime
    91 test/testintersections
    92 test/testjoystick
    93 test/testkeys
    94 test/testloadso
    95 test/testlock
    96 test/testmessage
    97 test/testmultiaudio
    98 test/testnative
    99 test/testoverlay2
   100 test/testplatform
   101 test/testpower
   102 test/testfilesystem
   103 test/testrelative
   104 test/testrendercopyex
   105 test/testrendertarget
   106 test/testresample
   107 test/testrumble
   108 test/testscale
   109 test/testsem
   110 test/testshader
   111 test/testshape
   112 test/testsprite2
   113 test/testspriteminimal
   114 test/teststreaming
   115 test/testthread
   116 test/testtimer
   117 test/testver
   118 test/testviewport
   119 test/testwm2
   120 test/testbounds
   121 test/torturethread
   122 test/testdisplayinfo
   123 test/testqsort
   124 test/testaudiocapture
   125 test/*.exe
   126 test/*.dSYM
   127 buildbot
   128 test/buildbot