Strange images with VSYNC

Strange things happen with the picture, e.g .:
and every few frames in the game I run SDL_RenderPresent twice in a row, then the image appears to me as if it was moved back in time, as if it had been omitted earlier. Sometimes garbage appears on the screen as well.
What’s going on ?
If I put SDL_Delay in between both SDL_RenderPresent then it’s OK.

Is there a reason you’re enabling vsync that way? What happens if you use the SDL_RENDERER_PRESENTVSYNC flag when creating the renderer instead?

And is there a reason you’re calling SDL_RenderPresent() multiple times in one frame? If you haven’t submitted anything to draw or at least cleared the frame then when it does the page flip it’s flipping to a frame in the swapchain that hasn’t been erased and drawn over, which is why it looks like it’s going back in time (showing an earlier frame) or miscellaneous junk.

1 Like

That’s entirely to be expected. This is what the documentation for SDL_RenderPresent() says: “The backbuffer should be considered invalidated after each present; do not assume that the previous contents will exist between frames. You are strongly encouraged to call SDL_RenderClear() to initialize the backbuffer before starting each new frame’s drawing, even if you plan to overwrite every pixel”.

I wouldn’t do it for no reason … It’s such a timed delay.
It’s not like he always goes back to the previous frame.
Every 2 frames gives an additional SDL_RenderPresent. I added writing the frame number on the screen and it shows me the order: 1 0 3 2 5 4 7 6 9 8 …

Doesn’t matter what it shows - you’re not using the API like it’s supposed to be used so anything can happen.

Also, you haven’t explained what you’re trying to achieve with calling SDL_RenderPresent() without rendering first

1 Like