[SDL] SDL_UpdateTexture crash when called from another thread...

Jared Maddox absinthdraco at gmail.com
Sun Jan 24 10:02:29 PST 2016


> Date: Wed, 20 Jan 2016 11:22:44 +0000
> From: "pik33" <pik33 at o2.pl>
> To: sdl at lists.libsdl.org
> Subject: [SDL] SDL_UpdateTexture crash when called from another
>         thread...
> Message-ID: <1453288964.m2f.49698 at forums.libsdl.org>
> Content-Type: text/plain; charset="iso-8859-1"
>
> .. in Linux, but not in Windows.
>
> I wrote a program (a smple SID player) with Lazarus/Freepascal (you can
> download it here:
>  http://eksperymenty.edu.pl/index.php/en/sid-player/2-uncategorised/23-a-nostalgic-sid-player
> ).
>
> The program works like this: it initializes SDL in the main thread, then it
> starts another thread, which then do all display things in the loop while the
> main program opens files, and does the rest of needed things.
>
> The thread code looks like this:
>

<snip>

> In Windows all works as expected. In Linux (Mint, x64, Nvidia 760) I got
> segmentation fault when  using proprietary Nvidia driver or simply nothing
> (the SDL window with garbage copied from the background) when using Nouveau.
>
> Then I disabled the thread and added  this screen refreshing stuff to the
> main loop. Then it worked. Some things are of course broken, because this
> screen refreshing thing was supposed to run in parallel with the rest of the
> program, but I have a screen looking as expected.
>
> So the obvious solution is to rewrite all the code, to make screen refresh in
> the main loop and the rest SDL unrelated things in another thread(s). This
> needs a lot of work.
>
> Is there any solution to make this thread run or is it simply impossible in
> Linux to do this and I have to rewrite the code?
>

Graphical adapter code should only be expected to work on the main
thread. Ths is true for all platforms. Some platforms will allow it to
work in more situations (Windows uses COM to convert multi-threaded to
single-threaded, X11 can operate fully multi-threaded in cross-network
configurations, etc.), but the only situation that you can count on is
running from the main thread. Thus, if you want multi-threaded
behavior you should leave graphics in the main thread, and push
everything else into another thread, instead of the other way around.

It might also be the case that you aren't updating the event queue
properly, but I think this is a driver issue. Cram the bulk of the
"main loop" code into a function, put a minimalist "main loop" into
the TRetro.Execute function (you need it to update the events queue),
and swap the positions of the functions.


More information about the SDL mailing list