diff --git a/scripts/modules/bpy_hydra.py b/scripts/modules/bpy_hydra.py index 1329c74b344c..5fd60ef1ae2a 100644 --- a/scripts/modules/bpy_hydra.py +++ b/scripts/modules/bpy_hydra.py @@ -63,7 +63,6 @@ class HydraRenderEngine(bpy.types.RenderEngine): return _bpy_hydra.engine_free(self.engine_ptr) - del self.engine_ptr @classmethod def register(cls): @@ -95,6 +94,8 @@ class HydraRenderEngine(bpy.types.RenderEngine): def update(self, data, depsgraph): engine_type = 'PREVIEW' if self.is_preview else 'FINAL' self.engine_ptr = _bpy_hydra.engine_create(self.as_pointer(), engine_type, self.delegate_id) + if not self.engine_ptr: + return for key, val in self.get_sync_settings(engine_type).items(): _bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val) @@ -114,6 +115,8 @@ class HydraRenderEngine(bpy.types.RenderEngine): def view_update(self, context, depsgraph): if not self.engine_ptr: self.engine_ptr = _bpy_hydra.engine_create(self.as_pointer(), 'VIEWPORT', self.delegate_id) + if not self.engine_ptr: + return for key, val in self.get_sync_settings('VIEWPORT').items(): _bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index d4cd901dbdc4..6db6920a31a2 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -23,7 +23,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name)); /* USD has limited support for Vulkan. To make it works USD should be built * with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */ @@ -39,6 +38,11 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) hd_drivers.push_back(&hgi_driver_); } + render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name)); + + if (!render_delegate_) { + throw std::runtime_error("Cannot create render delegate: " + render_delegate_name); + } render_index_.reset(pxr::HdRenderIndex::New(render_delegate_.Get(), hd_drivers)); free_camera_delegate_ = std::make_unique( diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index f0c922194881..3aff44b38b36 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -65,23 +65,30 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) RenderEngine *bl_engine = (RenderEngine *)PyLong_AsVoidPtr(pyengine); - Engine *engine; - if (STREQ(engine_type, "VIEWPORT")) { - engine = new ViewportEngine(bl_engine, render_delegate_id); - } - else if (STREQ(engine_type, "PREVIEW")) { - engine = new PreviewEngine(bl_engine, render_delegate_id); - } - else { - if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { - engine = new FinalEngineGL(bl_engine, render_delegate_id); + Engine *engine = nullptr; + try { + if (STREQ(engine_type, "VIEWPORT")) { + engine = new ViewportEngine(bl_engine, render_delegate_id); + } + else if (STREQ(engine_type, "PREVIEW")) { + engine = new PreviewEngine(bl_engine, render_delegate_id); } else { - engine = new FinalEngine(bl_engine, render_delegate_id); + if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { + engine = new FinalEngineGL(bl_engine, render_delegate_id); + } + else { + engine = new FinalEngine(bl_engine, render_delegate_id); + } } } + catch (std::runtime_error &e) { + CLOG_ERROR(LOG_RENDER_HYDRA, "%s", e.what()); + } - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %016llx %s", engine, engine_type); + if (engine) { + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %016llx %s", engine, engine_type); + } return PyLong_FromVoidPtr(engine); }