vtkWindowToImageFilter giving artifacts


OS: Ubuntu 18.04 Server

I am running an API which processes an input mesh, takes screenshots of it and return some output. Other parts of the screen appearing as ghosts in the screenshot, lower left corner if the display is being used while the API is running.