Catch Out of memory error and display a nice error message
I would like to propose a small improvement for the situation, where the machine on which the renderer runs does not have enough free RAM. Maybe it is better to fail gracefully and catch the OOM and display a nice message instead of the python stack trace?
map-machine render --cache /maps/cache -z 19 -o /maps/cotopaxi.svg -b" -78.551165,-0.745289,-78.276507,-0.513904"
INFO Constructing ways...
INFO Constructing nodes...
INFO Drawing ways...
Traceback (most recent call last):
File "/usr/local/bin/map-machine", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/map_machine/main.py", line 32, in main
mapper.render_map(arguments)
File "/usr/local/lib/python3.9/site-packages/map_machine/mapper.py", line 316, in render_map
map_.draw(constructor)
File "/usr/local/lib/python3.9/site-packages/map_machine/mapper.py", line 92, in draw
occupied = Occupied(
File "/usr/local/lib/python3.9/site-packages/map_machine/pictogram/point.py", line 27, in init
self.matrix = np.full((int(width), int(height)), False, dtype=bool)
File "/usr/local/lib/python3.9/site-packages/numpy/core/numeric.py", line 343, in full
a = empty(shape, dtype, order)
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 8.23 GiB for an array with shape (102399, 86271) and data type bool
Oh. Thank you! I've never tested it for such a big pictures.
Yes, I think firstly I should add some error handling, but the overlap computing algorithm itself is quite primitive. I have to make it more optimal in the future.
I've added simple wrapping for this part of code, but on my computer this leads to SIGKILL and not an numpy exception.
I'll think on how to rewrite the overlap algorithm to support such cases.