What does SDL_LockSurface do?

i know the definition of SDL_LockSurface, but if i do not use SDL_LockSurface what will happen? Such as i need use a surface at different thread without lock the surface. does it cause some errors like segment fault

You should always use SDL_LockSurface().

It does not have anything to do with threads, it ensures that no one else
has access to the graphics hardware at the same time, thus avoiding
corrupt data.

regards,
PauloOn Fri, Mar 19, 2010 at 7:58 AM, peng6sl wrote:

i know the definition of SDL_LockSurface, but if i do not use
SDL_LockSurface what will happen? Such as i need use a surface at different
thread without lock the surface. does it cause some errors like segment
fault


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

Use SDL_LockSurface() when you want to read or write to
surface->pixels unless SDL_MUSTLOCK evaluates to false. If two threads
want to write to surface->pixels, you will need to build some
concurrency on top of that again. The SDL documentation warns about
calling system calls while a surface is locked, so tread (and thread I
suppose) carefully. If you want to manipulate surfaces from different
threads, you should be using software surfaces exclusively (as
SDL_MUSTLOCK should evaluate to false with them).On 19 March 2010 06:58, peng6sl wrote:

i know the definition of SDL_LockSurface, but if i do not use
SDL_LockSurface what will happen? Such as i need use a surface at different
thread without lock the surface. does it cause some errors like segment
fault


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

Locking is also called mapping and it is a way of accessing video memory using local memory address space. This means that surface->pixels may not be a valid pointer unless surface is first locked. Locking involves telling the video driver that this specific data is now being used by application code and should not be used by the driver until it is unlocked and control over data returned back to the driver.