Fix crash after last image is closed.