Is there a way to avoid having a picture that trails off the end of a page, as in this example?

This is how I wrap the picture:
\begin{wrapfigure}{r}{0.5\textwidth}
\vspace{-20pt}
\begin{center}
\includegraphics[width=0.4\textwidth]{./pictures/DBuserTabel.png}%{./Pictures/mainscreen1.png}
\caption{Uklip af User tablen i Databasen}
\label{fig:databaseUserTable}
\end{center}
\vspace{-20pt}
\vspace{1pt}
\end{wrapfigure}




\centeringover\begin{center}[...]\end{center}, because the environment produces whitespace which one usually don't want in your figures. #tookmeyearstofindout – Bananguin Mar 27 '17 at 13:16\clearpagecommand before my wrapfigure and the text paragraph that comes after that. This way, the entire thing is guaranteed to start on a new page, which solves this problem. – Marie M. Mar 23 '22 at 16:13