I want to use render_data function within an undo() context because otherwise the annotation rendering modified the material of several background objects in my scene. I want to run it in a loop for several modifications of some objects. The script run for only the first time and then I got an error "ReferenceError: StructRNA of type Scene has been removed" in https://github.com/DIYer22/bpycv/blob/0ff76443642544e7459024e37b28f2bc1d8cce90/bpycv/render_utils.py#L35
I want to use render_data function within an undo() context because otherwise the annotation rendering modified the material of several background objects in my scene. I want to run it in a loop for several modifications of some objects. The script run for only the first time and then I got an error "ReferenceError: StructRNA of type Scene has been removed" in https://github.com/DIYer22/bpycv/blob/0ff76443642544e7459024e37b28f2bc1d8cce90/bpycv/render_utils.py#L35
As I saw from your code in https://github.com/DIYer22/bpycv/blob/0ff76443642544e7459024e37b28f2bc1d8cce90/bpycv/render_utils.py#L17 you use some global variables, e.g. for the scene. While for other cases you don't https://github.com/DIYer22/bpycv/blob/0ff76443642544e7459024e37b28f2bc1d8cce90/bpycv/pose_utils.py#L24
The error I got above was due to the global scene variable which refers to deleted data, caused due to the undo operation. Such behavior is described in Blender documentation https://docs.blender.org/api/blender2.8/info_gotcha.html#undo-redo
A working modfication is to override the global scene variable and re-obtain it from the context within here https://github.com/DIYer22/bpycv/blob/0ff76443642544e7459024e37b28f2bc1d8cce90/bpycv/render_utils.py#L25.
I don't know however where else these global variables are used.