USD export: prototype invoking Python chasers #108823

Merged
Michael Kowalski merged 35 commits from makowalski/blender:test-usd-export-chaser into main 2023-08-07 23:02:54 +02:00
1 changed files with 3 additions and 7 deletions
Showing only changes of commit aa6768cda2 - Show all commits

View File

@ -102,9 +102,7 @@ struct USDSceneExportContext {
struct USDMaterialExportContext {
USDMaterialExportContext() {}
USDMaterialExportContext(pxr::UsdStageRefPtr in_stage) : stage(in_stage)
{
}
USDMaterialExportContext(pxr::UsdStageRefPtr in_stage) : stage(in_stage) {}
pxr::UsdStageRefPtr get_stage()
{
@ -181,10 +179,8 @@ static void handle_python_error(USDHook *hook)
python::object formatted = python::str("\n").join(formatted_list);
std::string err_msg = python::extract<std::string>(formatted);
makowalski marked this conversation as resolved Outdated

I'm unsure why there is custom code to print exceptions, I feel like this should either be trivial with the Python C API already, or there is some code to share with the rest of Blender.

Can you use PyC_Err_PrintWithFunc or perhaps directly PyErr_Print() to print the exception? For other cases we print the stacktrace to the console, I think we can do the same here.

I'm unsure why there is custom code to print exceptions, I feel like this should either be trivial with the Python C API already, or there is some code to share with the rest of Blender. Can you use `PyC_Err_PrintWithFunc` or perhaps directly `PyErr_Print()` to print the exception? For other cases we print the stacktrace to the console, I think we can do the same here.

Hi Brecht. I appreciate the comment. I was using PyErr_Print() originally, but was concerned the user might not notice the error in the console. The work here is to display the full exception error message text as a Blender error, so it would be more obvious. But I certainly see your point that this might be excessive. Perhaps a compromise might be to use PyErr_Print() to print the exception details and report a short, high level message in Blender. So, maybe line 183 can be:

WM_reportf( RPT_ERROR, "An exception occurred invoking USD hook '%s'. Please see the console for details", hook->name);

Would this be acceptable?

Hi Brecht. I appreciate the comment. I was using `PyErr_Print()` originally, but was concerned the user might not notice the error in the console. The work here is to display the full exception error message text as a Blender error, so it would be more obvious. But I certainly see your point that this might be excessive. Perhaps a compromise might be to use `PyErr_Print()` to print the exception details and report a short, high level message in Blender. So, maybe line 183 can be: `WM_reportf( RPT_ERROR, "An exception occurred invoking USD hook '%s'. Please see the console for details", hook->name);` Would this be acceptable?

Yes, that's fine and consistent with other Python error reporting I think.

Yes, that's fine and consistent with other Python error reporting I think.
WM_reportf(RPT_ERROR,
"An exception occurred invoking USD hook '%s':\n%s",
hook->name,
err_msg.c_str());
WM_reportf(
RPT_ERROR, "An exception occurred invoking USD hook '%s':\n%s", hook->name, err_msg.c_str());
}
class USDHookCall {