SDL_LockSurface slows my app to a crawl

I have 3 surfaces, they all need a lock to perform the reads and writes
i need. Locking screen and characterbasetileset is not a problem and my
app continues running at its normal speed of 200fps. However the lock
for part1_t2_tilesetsurface takes forever and drops my fps to 30-60. I
have tried the code below actually, even if all I do it lock the surface
and perform no pixel operations it has the same effect. Yet screen and
characterbase dont have any speed issues… ? What would be some things
to look for to resolve this lock speed issue?

SDL_LockSurface (screen);
SDL_LockSurface (characterbasetileset);
SDL_LockSurface (part1_t2_tilesetsurface);

for (Uint32 iy = 0; iy <= 20; iy++)
{
for (Uint32 ix = 0; ix <= 20; ix++)
{
// read & write pixels and stuff
}
}

SDL_UnlockSurface (t2_tilesetsurface);
SDL_UnlockSurface (characterbasetileset);
SDL_UnlockSurface (screen);

thanks :)–
Matt Pruett <@Matt_Pruett>

Quoth Matt Pruett , on 2005-07-05 10:36:16 -0700:

I have 3 surfaces, they all need a lock to perform the reads and writes
i need. Locking screen and characterbasetileset is not a problem and my
app continues running at its normal speed of 200fps. However the lock
for part1_t2_tilesetsurface takes forever and drops my fps to 30-60.

Firstly, you may not need to lock the surface. If
SDL_MUSTLOCK(part1_t2_tilesetsurface) returns 0 then you can access
the surface pixels at any time without locking it. Secondly:

SDL_LockSurface (part1_t2_tilesetsurface);
[…]
SDL_UnlockSurface (t2_tilesetsurface);

This doesn’t seem to be what you intended… ?

—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050705/d2c0d5c5/attachment.pgp

Matt Pruett a ?crit :

I have 3 surfaces, they all need a lock to perform the reads and writes
i need. Locking screen and characterbasetileset is not a problem and my
app continues running at its normal speed of 200fps. However the lock
for part1_t2_tilesetsurface takes forever and drops my fps to 30-60. I
have tried the code below actually, even if all I do it lock the surface
and perform no pixel operations it has the same effect. Yet screen and
characterbase dont have any speed issues… ? What would be some things
to look for to resolve this lock speed issue?

SDL_LockSurface (screen);
SDL_LockSurface (characterbasetileset);
SDL_LockSurface (part1_t2_tilesetsurface);

for (Uint32 iy = 0; iy <= 20; iy++)
{
for (Uint32 ix = 0; ix <= 20; ix++)
{
// read & write pixels and stuff
}
}

SDL_UnlockSurface (t2_tilesetsurface);
SDL_UnlockSurface (characterbasetileset);
SDL_UnlockSurface (screen);

If you lock/unlock a lot, and find it too slow, you may want to try
software surfaces instead of hardware ones.

That said, I don’t think doing direct pixel access is the right thing to
do any more. The fastest way is probably to switch to a full blit-based
rendering. i.e have all your sprites in hardware surfaces and use only
blitting operations to create the rendering.

Stephane