diff --git a/scripts/modules/bpy_hydra.py b/scripts/modules/bpy_hydra.py index 41acda4e99b3..2511d9937ede 100644 --- a/scripts/modules/bpy_hydra.py +++ b/scripts/modules/bpy_hydra.py @@ -38,7 +38,6 @@ __all__ = ( import os import platform -import traceback from pathlib import Path import bpy @@ -107,21 +106,14 @@ def export_mtlx(material): """ Exports material to .mtlx file. It is called from Blender source code. """ try: import materialx.utils as mx_utils - - doc = mx_utils.export(material, None) - if not doc: - return "" - - mtlx_file = mx_utils.get_temp_file(".mtlx", f"mat_{material.as_pointer():016x}") - mx_utils.export_to_file(doc, mtlx_file, export_deps=True, copy_deps=False) - return str(mtlx_file) - except ImportError: print("ERROR: no MaterialX addon available") + return "" - except: - # This is a placeholder, this code will be moved to C part later - # This code shouldn't raise any exception due to breaking refcounts on RenderEngine - traceback.print_exc() + doc = mx_utils.export(material, None) + if not doc: + return "" - return "" + mtlx_file = mx_utils.get_temp_file(".mtlx", f"mat_{material.as_pointer():016x}") + mx_utils.export_to_file(doc, mtlx_file, export_deps=True, copy_deps=False) + return str(mtlx_file) diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index e6793deacad4..380d9826d352 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -68,8 +68,28 @@ void MaterialData::init() Py_DECREF(result); } else { - CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, "Export error for %s", id->name); - PyErr_Print(); + /* Clearing and logging exception data */ + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + std::string err_str = ((PyTypeObject *)type)->tp_name; + if (value) { + PyObject *pstr = PyObject_Str(value); + err_str += ": "; + err_str += PyUnicode_AsUTF8(pstr); + Py_DECREF(pstr); + } + CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, + "Export error for %s (%s): %s", + prim_id.GetText(), + id->name, + err_str.c_str()); + if (traceback) { + PyTraceBack_Print(traceback, PySys_GetObject("stderr")); + } + Py_XDECREF(traceback); + Py_XDECREF(value); + Py_DECREF(type); } Py_DECREF(module);