Ending rendered viewport

Hi, had a question on blender entering in and out of rendered viewport mode.

I know that when it is entered a RenderEngine is created and it uses the view_draw and view_update calls to do it’s thing. What, if any, calls are made when the viewport is switched back to another mode? Is the RenderEngine instance destroyed then? Basically how is an external engine supposed to know that rendered viewport is no longer being used?

If it helps the reason I ask is our renderer (appleseed) continues running when the viewport is swiched out of rendered mode. It runs in a separate python thread so we’re not sure if that’s the issue or it’s something else.

1 Like

The Render Engine instance is destroyed in that case, so you can implement cleanup in the __del__ method.

Hi Brecht. I’m not sure if that’s actually happening (the engine destruction). We have a logger message in the del function and it doesn’t fire off when interactive mode is ended, so the function isn’t being callled for some reason. I do see the message when I quit blender though.

I can’t reproduce that issue, when changing the shading mode in the viewport the destructor is called for me:

import bpy

class CustomRenderEngine(bpy.types.RenderEngine):
    bl_idname = "custom_renderer"
    bl_label = "Custom Renderer"

    def __init__(self):
    def __del__(self):
    def view_update(self, context):
        print('view update')

    def view_draw(self, context):
        print('view draw')

def register():

def unregister():

if __name__ == "__main__":

Hey Brecht. We figured it out, but I had one more question.

When interactive is running and a material preview is requested, that leads to two RenderEngine instances existing simultaneously, correct? It seems that this combination occasionally causes Blender to lockup with appleseed. Is there any way to disable the material preview call when interactive mode is on?

There is no option for it at the moment. You could detect this case and not render previews then, but it will lead to empty preview images.

We made Cycles support multiple simulatenous render sessions in the same process, and as far as I know it the Blender render API should reliably work with it. Is this a known limitation in Appleseed, or just a bug somewhere that you’re trying to work around?

We’re not sure yet. One of the core devs is looking into it as there are other occasions where it locks up too