Blender hangs on first viewport update of custom RenderEngine

In the LuxCore addon for Blender, I create the viewport session during the first call of RenderEngine.view_update().

I have two problems:

  • I can not report progress to the user. RenderEngine.update_stats() does not work inside view_update.
  • The user can not cancel the viewport render, Blender hangs completely until the session is created. Annoying in heavy scenes.

Am I doing something wrong? Should I create my session in another method where all of the above works?
How does Cycles deal with this?

(My code)

view_update is blocking, because the data it needs to export is also accessed by the rest of the UI and tools. I guess this is what you mean by update_stats not working, that it doesn’t redraw the UI during view_update? I think test_break might work to detect if the user presses escape key, but that’s not great.

Cycles makes a distinction between exporting the data from Blender, and then doing things like loading image textures and building the BVH, which helps a bit. Not sure if you do or can do something similar. Other than that it suffers the same problem.

In general for this kind of heavy blocking operation we would like to keep the UI responsive, for example when opening file or subdividing a really heavy mesh. But the infrastructure is not there for it at the moment.

Yes, the whole Blender UI locks up until view_update is done.

No, this does not work (anyway, escape does not cancel a viewport render).

Thanks, I think I could implement something like this (in the first view_update only kick off the export, and show export progress in view_draw). I’ll have to test it.

That’s reassuring. I never noticed, probably because the initial export is so fast.

Cycles does most work in its own thread, and also calls update_stats from there. So you can show progress also outside view_draw, just not while view_update or view_draw is blocking the main Blender thread.