mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-29 12:20:41 +01:00
Protect map preview from exceptions
Since map preview is optional, an exception should not propagate to terrain calculation, so print an error message + traceback but keep the script running.
This commit is contained in:
parent
3644965842
commit
53f88d337d
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import numpy as np
|
||||
import sys, traceback
|
||||
|
||||
has_matplotlib = True
|
||||
try:
|
||||
@ -19,8 +20,6 @@ except ImportError: # No module matplotlib
|
||||
|
||||
if has_matplotlib:
|
||||
def view_map(dem, lakes, scale=1, title=None):
|
||||
if not has_matplotlib:
|
||||
return
|
||||
lakes_sea = np.maximum(lakes, 0)
|
||||
water = np.maximum(lakes_sea - dem, 0)
|
||||
max_elev = lakes_sea.max()
|
||||
@ -48,15 +47,21 @@ if has_matplotlib:
|
||||
plt.title(title, fontweight='bold')
|
||||
|
||||
def update(*args, t=0.01, **kwargs):
|
||||
plt.clf()
|
||||
view_map(*args, **kwargs)
|
||||
plt.pause(t)
|
||||
try:
|
||||
plt.clf()
|
||||
view_map(*args, **kwargs)
|
||||
plt.pause(t)
|
||||
except:
|
||||
traceback.print_exception(*sys.exc_info())
|
||||
|
||||
def plot(*args, **kwargs):
|
||||
plt.clf()
|
||||
view_map(*args, **kwargs)
|
||||
plt.pause(0.01)
|
||||
plt.show()
|
||||
try:
|
||||
plt.clf()
|
||||
view_map(*args, **kwargs)
|
||||
plt.pause(0.01)
|
||||
plt.show()
|
||||
except Exception as e:
|
||||
traceback.print_exception(*sys.exc_info())
|
||||
|
||||
else:
|
||||
def update(*args, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user