Moved check of existing MaterialX addon from bpy_hydra.py to material.cc and log warning only once. #83

Merged
Bogdan Nagirniak merged 3 commits from hydra-matx-check into hydra-render 2023-08-02 07:45:13 +02:00
Showing only changes of commit 5d03bf65ba - Show all commits

View File

@ -121,17 +121,19 @@ void MaterialData::export_mtlx()
if (!matx_addon_checked) { if (!matx_addon_checked) {
gstate = PyGILState_Ensure(); gstate = PyGILState_Ensure();
/* Adding second check into the lock, good practice to make this fully correct */
if (!matx_addon_checked) {

Can you add another if (!matx_addon_checked) after PyGILState_Ensure() to make this into a double checked lock? Not that it's likely to be a problem, but it's good practice anyway to make this fully correct.

Can you add another `if (!matx_addon_checked)` after `PyGILState_Ensure()` to make this into a double checked lock? Not that it's likely to be a problem, but it's good practice anyway to make this fully correct.
PyObject *mx_module = PyImport_ImportModule("materialx"); PyObject *mx_module = PyImport_ImportModule("materialx");
has_matx_addon = mx_module != nullptr; has_matx_addon = mx_module != nullptr;
Py_XDECREF(mx_module); Py_XDECREF(mx_module);
if (!has_matx_addon) { if (!has_matx_addon) {
PyErr_Print(); PyErr_Print();
CLOG_WARN(LOG_RENDER_HYDRA_SCENE, "No MaterialX addon, materials won't be exported."); CLOG_WARN(LOG_HYDRA_SCENE, "No MaterialX addon, materials won't be exported.");
}
matx_addon_checked = true;
} }
PyGILState_Release(gstate); PyGILState_Release(gstate);
matx_addon_checked = true;
} }
if (!has_matx_addon) { if (!has_matx_addon) {