SDL_Surface->pixels

Hi,

I would like to suggest something about the documentation of SDL_Surface:

The documentation says you should not access pixels without locking
previously. But if the surface has to be locked and you don’t do that,
SDL_Surface->pixels will be 0.
I don’t want to critisize these behavoiur, but I would appreciate it if it
was documented.

Furthermore I would like to ask what the SDL error message (when trying to
blit) means that says that the surface is busy (it isn’t locked according to
SDL_Surface->locked).

P.S. The background of this problem is that I wrote a C++ wrapper for
SDL_Surface which keeps it’s own pointer to pixels. And due to I have used
always windowed mode during development I wondered why the the App hangs up
in fullscreen mode.
I’m using SDL 1.1.8 in Windows 95 using a GeForce 2 MX.

Thanx in advance.–
Alexander Lauser

Hi,

I would like to suggest something about the documentation of SDL_Surface:

The documentation says you should not access pixels without locking
previously. But if the surface has to be locked and you don’t do that,
SDL_Surface->pixels will be 0.
I don’t want to critisize these behavoiur, but I would appreciate it if it
was documented.

It may not be documented because they don’t want to make it official that
SDL_Surface->pixels will be 0 when a lock is required. It just happens to
work that way right now.

When something isn’t officially mentioned in the docs, one should always be
careful about that, and not rely on the current behavior and assume it is
safe to use. Doing so only makes you application unstable.

Furthermore I would like to ask what the SDL error message (when trying to
blit) means that says that the surface is busy (it isn’t locked according
to
SDL_Surface->locked).

I believe that error only occurs when DirectX has lost the surface, or in
other words, the video memory that was allocated has been requisitioned by
another application (the Windows 95 desktop for example, because of an
Alt-tab) and is therefore “busy”, or being used elsewhere and not available
to you at this time. You can read up more on DirectX to understand all this
behavior in more detail.

P.S. The background of this problem is that I wrote a C++ wrapper for
SDL_Surface which keeps it’s own pointer to pixels. And due to I have used
always windowed mode during development I wondered why the the App hangs
up
in fullscreen mode.

It’s not a wise idea to keep pointers around to pixels. You should only
assume a pixel pointer will be valid so long as the surface is locked. When
it’s not locked, the pointer isn’t valid anymore. If you lock the surface
again, the old pointer isn’t valid anymore either. You should get the new
pointer instead. The way the system is set up, it’s flexible enough that
the pixel data could have been moved in memory to another location. Like I
said, be very careful about the assumptions you make, because those are
going to cause 99.99% of all your problems. If your app is hanging in
fullscreen mode, but doesn’t in windowed mode, it’s almost certainly due to
making bad assumptions, which are just now coming back to haunt you. Live
and learn, as they say. :slight_smile:

-Jason

----- Original Message -----
From: alxlaus@gmx.de (Alexander Lauser)
To: “SDL-Mailinglist”
Sent: Sunday, April 14, 2002 6:04 AM
Subject: [SDL] SDL_Surface->pixels