mac: Guard against closed window, fixes #536.