Strange flickering

Hi,

I’ve experienced some very strange flickering effect. I have these functions (pseudo-code…)

Draw(Object &ob)
{
if (redraw)
{
redraw = false;
ClearScreen();
}
SDL_BlitSurface(screen, ob.GetFrame(), ob.GetLocation());
}

Sync()
{
Delay();
Flip();
redraw = true;
}

If I call then

Draw(&dog);
Sync();

It draws the dog okay (no flicker), but if I have more than one sprites at once, like this

Draw(&dog);
Draw(&cat);
Sync();

all of them flicker badly. I’ve tried both SDL_SWSURFACE and SDL_HWSURFACE | SDL_DOUBLEBUF, I’ve tried to use SDL_UpdateRects, I’ve tried to erase the screen in different places but none of them works properly. It’d be nice to have at least two sprites at once… :wink: So, what’s the catch?–
– Ville Koskinen
@Ville_Koskinen
Finland

I’ve experienced some very strange flickering effect. I have these
functions (pseudo-code…)

all of them flicker badly. I’ve tried both SDL_SWSURFACE and
SDL_HWSURFACE | SDL_DOUBLEBUF, I’ve tried to use SDL_UpdateRects,
I’ve tried to erase the screen in different places but none of them
works
properly. It’d be nice to have at least two sprites at once… :wink: So,
what’s the catch?

Are you sure that there is enough space for two fullscreen surfaces in
your video memory?
I had a similar problem: I used SDL_HWSURFACE and SDL_DOUBLEBUF with
SDL_FULLSCREEN and did a flip after every time I rearranged my graphic
objects.
The result was a badly flickering animation.
The sdl detected not enough space for two video buffers, so it allocated
just one buffer and told me that everything is ok. But the output was
flickering.
After some testing, I recognized that all sprites were drawn on the
currently displayed surface - no double buffering take effect.
So I have reduced the color depth and now it works fantastic.

Perhaps the solution to your problem is similar to mine.

Good luck,
Christoph.

The sdl detected not enough space for two video buffers, so it allocated
just one buffer and told me that everything is ok. But the output was
flickering.

So when this failed without telling you,

(SDL_GetVideoSurface()->flags & SDL_DOUBLEBUF)

was non-zero? That would be telling you falsely that “everything is okay”.

SDL_SetVideoMode() only fails if the surface can’t be created at all;
certain missing features are emulated internally, some just get disabled,
but you always check the surface’s flags if there’s something you
absolutely can’t do without. This is in the docs.

However, if the surface wasn’t double-buffered when SDL claimed it was,
that’s a bug, and we’ll fix it.

–ryan.

Erhm, I’m almost too embarrassed to say this, but I had SDL_UpdataRect(0,0,0,0) in the Erase() function :^| … but thank you for your help. :slight_smile:

However, if the surface wasn’t double-buffered when SDL claimed it was,
that’s a bug, and we’ll fix it.

There’s no bug in the SDL. The only bug sat in my eyes …
I looked at my program’s debug-output just again, and everything is as it
should be: Double buffering was disabled.
Yesterday I could swear the output told me double buffering was enabled.

I’m sorry.

Christoph.