Skip to content

Commit a232eb9

Browse files
committed
Better error handling in tab
1 parent 9bd3d90 commit a232eb9

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/common_ui.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,24 @@ def run_generate(*inputs):
474474

475475
show_images = []
476476
inpainted_mesh_fi = mesh_simple_fi = None
477-
for input_i, type, result in gen_obj:
477+
msg = "" # Empty string is never returned
478+
while True:
479+
try:
480+
input_i, type, result = next(gen_obj)
481+
except StopIteration:
482+
# TODO: return more info
483+
msg = '<h3>Successfully generated.</h3>'
484+
break
485+
except Exception as e:
486+
traceback.print_exc()
487+
msg = '<h3>' + 'ERROR: ' + str(e) + '</h3>' + '\n'
488+
if 'out of GPU memory' not in msg:
489+
msg +=\
490+
'Please report this issue ' \
491+
f'<a href="https://github.com/thygate/{REPOSITORY_NAME}/issues">here</a>. ' \
492+
'Make sure to provide the full stacktrace: \n'
493+
msg += '<code style="white-space: pre;">' + traceback.format_exc() + '</code>'
494+
break
478495
if type == 'simple_mesh':
479496
mesh_simple_fi = result
480497
continue
@@ -507,5 +524,4 @@ def run_generate(*inputs):
507524
if backbone.get_opt('depthmap_script_show_3d_inpaint', True):
508525
if inpainted_mesh_fi is not None and len(inpainted_mesh_fi) > 0:
509526
display_mesh_fi = inpainted_mesh_fi
510-
# TODO: return more info
511-
return show_images, inpainted_mesh_fi, display_mesh_fi, 'Generated!'
527+
return show_images, inpainted_mesh_fi, display_mesh_fi, msg.replace('\n', '<br>')

src/core.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,23 +267,27 @@ def core_generation_funnel(outpath, inputimages, inputdepthmaps, inputnames, inp
267267
yield count, 'simple_mesh', meshsimple_fi
268268

269269
print("Computing output(s) done.")
270-
except RuntimeError as e:
271-
# TODO: display in UI
272-
if 'out of memory' in str(e):
273-
suggestion = "ERROR: out of GPU memory, could not generate depthmap! " \
270+
except Exception as e:
271+
import traceback
272+
if 'out of memory' in str(e).lower():
273+
print(str(e))
274+
suggestion = "out of GPU memory, could not generate depthmap! " \
274275
"Here are some suggestions to work around this issue:\n"
275276
if inp[go.BOOST]:
276277
suggestion += " * Disable BOOST (generation will be faster, but the depthmap will be less detailed)\n"
277-
if backbone.USED_BACKBONE == backbone.BackboneType.WEBUI:
278+
if backbone.USED_BACKBONE != backbone.BackboneType.STANDALONE:
278279
suggestion += " * Run DepthMap in the standalone mode - without launching the SD WebUI\n"
279280
if device != torch.device("cpu"):
280281
suggestion += " * Select CPU as the processing device (this will be slower)\n"
281282
if inp[go.MODEL_TYPE] != 6:
282-
suggestion += " * Use a different model (this could reduce quality)\n"
283+
suggestion +=\
284+
" * Use a different model (generally, more memory-consuming models produce better depthmaps)\n"
283285
if not inp[go.BOOST]:
284286
suggestion += " * Reduce net size (this could reduce quality)\n"
285-
print(f"{suggestion}")
287+
print('Fail.\n')
288+
raise Exception(suggestion)
286289
else:
290+
print('Fail.\n')
287291
raise e
288292
finally:
289293
if backbone.get_opt('depthmap_script_keepmodels', True):

0 commit comments

Comments
 (0)