Fixed occasional crash when leaving a map