Fix a crash when switching focus from a non-managed window.
Fix a crash when trying to reflow without any layouts.
Fix two crashes when trying to swap focused window to main.