2.8 EXCEPTION_ACCESS_VIOLATION during pysind2 script execution


I have a script running in Pyside2 in its own thread, its persistent window that never closes and remain in that thread during the blender live cycle.

When I try to run a render via bpy.ops.render.render(write_still=1) there is 50% chance I get

Address : 0x00007FF765FF38B0
Module  : C:\Program Files\Blender Foundation\Blender 2.83\blender.exe

I’m guessing its due to some thread synchronization or something, as this "Addon" does not align too properly to blender addon guide as I’m using PySide2.

In any case, does any1 have any idea why I’m getting these crashes when I try to render? How can I tell blender to render from other threads? As far as I can tell when the render “works” the Qt GUI becomes frozen, but blender GUI still remains “responsive” which tells me that I must be starting the render from Qt thread and not blender own thread & causing an error…

Any hints would be great

edit. my render script goes as follow:

    for camera in cameraList:
        bpy.context.scene.camera = bpy.data.objects[camera]
        bpy.data.scenes[0].render.filepath = self.mRootPath + "/" + str(camera) + "." + self.mFormat
        print("render", self.mRootPath + "/" + str(camera) + "." + self.mFormat)
        print("pass render ")

error happens on bpy.ops.render.render(write_still=1)

If you are editing Blender data structures or calling operators, that must always happen in the main thread, not a thread created by Qt. If you receive the event from Qt in another thread, you can somehow pass that event along to the main thread, maybe storing it in a queue and passing it along to a timer created with bpy.app.timers.

Hey @brecht
Yes I believe that was my issue, I was calling render function from qt thread and causing blender to go bananas. I’m currently trying to research how can I push my current/future requests from my qt thread to main blender thread, any hints would be great :- )

Will report once I make some progress.