Window previews are partially or completely black

For newly created windows, the preview shown in the dock sometimes is completely or partially black instead of showing the window's contents (although the window itself is not black).

This happens especially for applications which open many main windows at the same time at startup (e.g. starting libre office from the command line with many documents with "lowriter *.odt &" or starting several atril instances with "atril *.pdf &"). Making the affected window active, changing or scrolling its content, and then showing its preview again while being the active window usually fixes the black preview.

Another "black" effect happens when thunar is started: I've an auto-hide bottom panel (i.e. the panel pops up on top of the lower part of other windows), and when I start thunar fullscreen and then look at its preview, the area taken up by the panel and by the preview of the thunar window is black in the preview, and the rest of the thunar window is shown correctly in the preview. Same for some other applications (e.g. zim and libreoffice), but not for all (the terminal, firefox and thunderbird don't seem to have that problem).

Moreover, the preview of some applications recursively shows a miniature copy of their own preview.