[Flickering Problem] Help / direction needed to resolve flickering problem on a game

Started by
1 comment, last by Shaarigan 2 years, 8 months ago

Hi any SDL2 Guru out there,

I am currently trying to make a “brick breaker” game that i learnt in udemy and converting it to be more object oriented for my capstone C++ project on Udacity. As i have finished the game, i noticed that i kept facing the problem whereby the render keep flickering. I went to see many other post out there about flickering and i tried to implement the solution that was suggested such as using double buffer “Renderclear→Rendercopy→ Renderpresent” but to no avail i couldn't find the problem causing it. I tried on two different PCs and i realized the flicker happen randomly and the rate of flickering is different from different PCs. I am wondering if there is any experts / guru could lend a help to look through my game, i appreciate if they could point me to some direction on what is causing it?

Attached link is to my github where i have commit my code, pardon me for any beginner mistakes as i am trying to learn C++ and SDL.

https://github.com/WinRobotics/udacity-CppND-Capstone-BrickBreaker

Advertisement

I'm no SDL guru but I see a problem in your update (except for that it should be handleEvents and not HandlerEvents). You don't poll for all events but only for 1 and so there might be events in the background which involve those flickering. The usual game loop looks like this

while(run)
{
    while(os_events)
    {
        processEvent
    }
    Update
    Render
}

So what may happen is that the OS is sending events coming from the window manager which tries to update the screen. Those events can have multiple parts like getting the window decoration area, painting the decoration area, getting the client area, painting the client area. If you render regardless of what messages you get from the OS, you might interrupt a repaint message and so painting before the window manager has completed the buffer transfer. This leads to flickering!

This topic is closed to new replies.

Advertisement