Fix viewport tearing issue

Hey @adrian17 this should fix the issues with it. I think the main reason it was using up CPU time was because I had written all of those comparisons wrong.