SDL_LockTexture hangs program

I’m developing a program with SDL in C++ using Visual Studio. At the start of the program I create a texture with SDL_TEXTUREACCESS_STREAMING. I then create a 2nd thread passing the SDL_Texture pointer SDL_CreateTexture returns. In the 2nd thread I use SDL_LockTexture with this texture pointer. Depending on what seems timing issues, that’s the end of it, the program hangs, the message loop in the main thread (using SDL_WaitEvent) isn’t producing new events. Sometimes LockTexture works and returns however, and I get the expected result. What could be the cause of this?

EDIT: I tried to create the texture with SDL_TEXTUREACCESS_STATIC, and use SDL_UpdateTexture, but here again, the program hangs most of the time (this time on SDL_UpdateTexture).

You can’t share a texture between threads, all accesses to the texture must be from the thread in which it was created. You can share a surface however, so maybe you can rework what you want to do that way.

1 Like

Damn, that’s a nasty limitation, and something in need of official documentation. But in my case, using surfaces is probably workable, as I have software buffers anyway. Thanks a lot for the suggestion!