# LTDC STMF32 Double buffering problem

I'm trying to do double buffering using the hardware, STMF32492I.. so first I'm initalizing two layers in two different addresses.

Then I write to the back buffer, switch the back buffer..

But The problem I get multiple copies of the sprite that is animated, so its either I'm drawing to the front buffer multiple times, or the back buffer needs to be cleared.

Here is how I'm doing it

void main
{
while (1)
{

LTDC_switch_framebuffer();
// draw spries
}
}

void LTDC_switch_framebuffer(void)
{

while ((LTDC->CDSR & LTDC_CDSR_VSYNCS) == 0);    // wait for reload
;
flip ^= 1;
BSP_LCD_SetLayerVisible(flip, ENABLE);
BSP_LCD_SelectLayer(1-flip);

}