geometry: add some null pointer checks (fixes #8433)