-------- Edit --------
To avoid crashes on render time it’s better not to use modal timer to manage frame change. A handler is better such as frame_change_post. But the script will work properly in this case only if it doesn’t call any context.
This was the problem(s) on my script. I was toggling between edit and object mode. Bad idea…
Now it’s ok, thanks to Atom. No more context in the main calculation, and I use frame_change_post handler.
Hi everyone,
I’m new to blender, new to python, and new to blender artist… so I hope I won’t do too many wrong things.
I attached a blend file which is a simplification of a complex script I wrote and which does the job. The original script calculates the vertices of an infinite plane that are in the field of the camera. As I’m not comfortable with handlers, I used a timer that checks if camera world matrix has changed. If so, my script re-calculates the vertices that must be displayed. It works fine on playback. But when rendering the animation, blender crashes, sometimes after one frame render, sometimes after 10. I introduced a sleep time using a frame_change_post handler. It helped but not as I hoped. I still experience crashes after 3 to 50 frame renders.
I suppose it is a wrong idea to use a timer. Maybe the script is changing data when blender is trying to render. In fact I don’t know how blender works. And I don’t know how to make the render wait for the end of the scene update before starting. I would like to use handlers
So, as a simplification of my original script, I posted a blend file (hope it works). There is a plane that follows an empty (easier than a camera field). In the tool bar (T key) there is a refresh button that calculates the plane coordinates according to the empty ones (I didn’t use any timer here). So if you change the frame in the timeline, then press the refresh button, it works.
Now, I want to call my “exec_calc” function from an handler. For that, I (you) uncomment the last line of the script and add ‘scn’ as argument in “exec_calc” function (otherwise the handler doesn’t call my function properly).
The result is strange :
When I change the frame in the timeline, my plane disappears as if only half of my script worked, but I have no error in my console. And if I hit the render button, my plane is rendered as it should and I have the following message in the console :
Traceback (most recent call last):
File “/home/olivier/Blender/Tests/plane_test.blend/plane_test”, line 33, in exec_calc
File “/home/olivier/Blender/Tests/plane_test.blend/plane_test”, line 14, in empty_plane
File “/usr/share/blender/2.69/scripts/modules/bpy/ops.py”, line 188, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.mode_set.poll() failed, context is incorrect
So there is a context problem. When I use the refresh button (or a timer) to call my “exec_calc” function, I don’t have any context problem. When I use a handler, I have a context problem.
Why and how to solve this problem ? And if somebody could help me to understand how to avoid crash problems on render time, it would be fine. For me, blender python API is not helpful, it’s too difficult to understand.
Thanks in advance.
Attachments
plane_test.blend (496 KB)