Fix crash when clicking UI early. Fixes #2196