mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-01-01 14:00:36 +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
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import sys, traceback
|
||||||
|
|
||||||
has_matplotlib = True
|
has_matplotlib = True
|
||||||
try:
|
try:
|
||||||
@ -19,8 +20,6 @@ except ImportError: # No module matplotlib
|
|||||||
|
|
||||||
if has_matplotlib:
|
if has_matplotlib:
|
||||||
def view_map(dem, lakes, scale=1, title=None):
|
def view_map(dem, lakes, scale=1, title=None):
|
||||||
if not has_matplotlib:
|
|
||||||
return
|
|
||||||
lakes_sea = np.maximum(lakes, 0)
|
lakes_sea = np.maximum(lakes, 0)
|
||||||
water = np.maximum(lakes_sea - dem, 0)
|
water = np.maximum(lakes_sea - dem, 0)
|
||||||
max_elev = lakes_sea.max()
|
max_elev = lakes_sea.max()
|
||||||
@ -48,15 +47,21 @@ if has_matplotlib:
|
|||||||
plt.title(title, fontweight='bold')
|
plt.title(title, fontweight='bold')
|
||||||
|
|
||||||
def update(*args, t=0.01, **kwargs):
|
def update(*args, t=0.01, **kwargs):
|
||||||
plt.clf()
|
try:
|
||||||
view_map(*args, **kwargs)
|
plt.clf()
|
||||||
plt.pause(t)
|
view_map(*args, **kwargs)
|
||||||
|
plt.pause(t)
|
||||||
|
except:
|
||||||
|
traceback.print_exception(*sys.exc_info())
|
||||||
|
|
||||||
def plot(*args, **kwargs):
|
def plot(*args, **kwargs):
|
||||||
plt.clf()
|
try:
|
||||||
view_map(*args, **kwargs)
|
plt.clf()
|
||||||
plt.pause(0.01)
|
view_map(*args, **kwargs)
|
||||||
plt.show()
|
plt.pause(0.01)
|
||||||
|
plt.show()
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exception(*sys.exc_info())
|
||||||
|
|
||||||
else:
|
else:
|
||||||
def update(*args, **kwargs):
|
def update(*args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user