Avoid a use-after-free.

This was a bug on all platforms, but it seems that OSX delivers events
with timing that exposes the bug. Hopefully deals with the qqx crashes
on OSX.
Fix a conditional mess-up on Windows.