Fix crash on window resize

Fixes #757.