SDL_Surface, SDL_Texture and multithreading

Hello,

I’m creating a multithreaded program and have a question:

I’ve heard that SDL-specific functions, such as SDL_CreateTexture and SDL_CreateTextureFromSurface, should only be executed from the thread that created the SDL window, i.e the main thread.

What I do in my program to prevent this is using SDL_Image’s function IMG_Load to load an image and saves it into a SDL_Surface. This is made in another thread (a loading-thread). Then, in the main-thread, I’m creating the final texture by calling the SDL_CreateTextureFromSurface function, and passing the SDL_Surface into it.

Is it safe to call IMG_Load in another thread and creating the SDL_Surface the way I do?

I’m doing the same thing in both Linux and Windows. So far i haven’t seen any problems.Sent from my ASUS

----- Original Message -----
From: danielane85 at hotmail.com (Naith)
Sent:Sat, 02 Apr 2016 07:08:40 +0700
To:sdl at lists.libsdl.org
Subject:[SDL] SDL_Surface, SDL_Texture and multithreading


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

As far as I’m concern, IMG_Load and SDL_Surface are cpu bound, so
loading and creating in a different thread is okay. If you are going to
create a texture, which is gpu bound, you have to do it in your main
thread or the thread, where you created the window with the opengl
context(SDL uses opengl for acceleration). Because opengl isn’t
multithreating capable, your way of doing it is right.–

Mit freundlichen Gr??en / Best regards

Frank Kevin Zey B.Sc. Informatik

On 04/03/2016 07:38 AM, wutipong.wongsakuldej at gmail.com wrote:

I’m doing the same thing in both Linux and Windows. So far i haven’t
seen any problems.

Sent from my ASUS

-------- Original Message --------
From:Naith
Sent:Sat, 02 Apr 2016 07:08:40 +0700
To:sdl at lists.libsdl.org
Subject:[SDL] SDL_Surface, SDL_Texture and multithreading

Hello,

I’m creating a multithreaded program and have a question:

I’ve heard that SDL-specific functions, such as SDL_CreateTexture and
SDL_CreateTextureFromSurface, should only be executed from the thread
that created the SDL window, i.e the main thread.

What I do in my program to prevent this is using SDL_Image’s function
IMG_Load to load an image and saves it into a SDL_Surface. This is
made in another thread (a loading-thread). Then, in the main-thread,
I’m creating the final texture by calling the
SDL_CreateTextureFromSurface function, and passing the SDL_Surface
into it.

Is it safe to call IMG_Load in another thread and creating the
SDL_Surface the way I do?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thank you both very much for your answers!