Fix crash on window resize

This fixes a bug that would sometimes trigger a fail! when the window was resized.