Fix crash when users close plot windows, re #8091