diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2008-07-27 02:00:26 +0400 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2008-07-27 02:00:26 +0400 |
commit | 8a295553f7fef22b67e3cb3be4d9881cfadedafc (patch) | |
tree | cdd9fcfe179773abb450810ae98ca989e6752bd2 | |
parent | 70ce017777dcaf0ddd68b9533eba8a926aceff1e (diff) |
== Python scriptlinks ==
Render/postrender events were missing from bg rendering (and also from rendering called inside scripts). Found this because of bug #17389, the code to prevent race conditions with pynodes is currently inside BPY_do_all_scripts (that runs scriptlinks) and so was not being called in bg mode or rendering via scripts.
http://projects.blender.org/tracker/?func=detail&atid=125&aid=17389&group_id=9
-rw-r--r-- | source/blender/python/api2_2x/sceneRender.c | 38 | ||||
-rw-r--r-- | source/creator/creator.c | 22 |
2 files changed, 54 insertions, 6 deletions
diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c index 8f251fc8452..22e165cbe9f 100644 --- a/source/blender/python/api2_2x/sceneRender.c +++ b/source/blender/python/api2_2x/sceneRender.c @@ -56,6 +56,7 @@ struct View3D; /* keep me up here */ #include "gen_utils.h" #include "gen_library.h" +#include "../BPY_extern.h" /* for BPY_do_all_scripts() */ #include "Scene.h" #include "Group.h" @@ -469,19 +470,20 @@ PyObject *M_Render_EnableDispWin( PyObject * self ) PyObject *RenderData_Render( BPy_RenderData * self ) { Scene *oldsce; + /* unlock to prevent a deadlock when there are pynodes: */ + PyThreadState *tstate = NULL; if (!G.background) { oldsce = G.scene; set_scene( self->scene ); + tstate = PyEval_SaveThread(); BIF_do_render( 0 ); set_scene( oldsce ); } - else { /* background mode (blender -b file.blend -P script) */ + int slink_flag = 0; Render *re= RE_NewRender(G.scene->id.name); - - int end_frame = G.scene->r.efra; if (G.scene != self->scene) @@ -490,11 +492,25 @@ PyObject *RenderData_Render( BPy_RenderData * self ) G.scene->r.efra = G.scene->r.sfra; + if (G.f & G_DOSCRIPTLINKS) { + BPY_do_all_scripts(SCRIPT_RENDER); + G.f &= ~G_DOSCRIPTLINKS; /* avoid FRAMECHANGED events*/ + slink_flag = 1; + } + + tstate = PyEval_SaveThread(); + RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + if (slink_flag) { + G.f |= G_DOSCRIPTLINKS; + BPY_do_all_scripts(SCRIPT_POSTRENDER); + } + G.scene->r.efra = end_frame; } + PyEval_RestoreThread(tstate); Py_RETURN_NONE; } @@ -565,12 +581,13 @@ PyObject *RenderData_SaveRenderedImage ( BPy_RenderData * self, PyObject *args ) PyObject *RenderData_RenderAnim( BPy_RenderData * self ) { Scene *oldsce; - /* this prevents a deadlock when there are pynodes: */ - PyThreadState *tstate = PyEval_SaveThread(); - + /* unlock to prevent a deadlock when there are pynodes: */ + PyThreadState *tstate = NULL; + if (!G.background) { oldsce = G.scene; set_scene( self->scene ); + tstate = PyEval_SaveThread(); BIF_do_render( 1 ); set_scene( oldsce ); } @@ -584,8 +601,17 @@ PyObject *RenderData_RenderAnim( BPy_RenderData * self ) if (G.scene->r.sfra > G.scene->r.efra) return EXPP_ReturnPyObjError (PyExc_RuntimeError, "start frame must be less or equal to end frame"); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_RENDER); + + tstate = PyEval_SaveThread(); RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_POSTRENDER); } + PyEval_RestoreThread(tstate); Py_RETURN_NONE; } diff --git a/source/creator/creator.c b/source/creator/creator.c index 9589f1e3e94..e17b0f66977 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -618,8 +618,23 @@ int main(int argc, char **argv) if (G.scene) { if (a < argc) { int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a]))); + int slink_flag= 0; Render *re= RE_NewRender(G.scene->id.name); + + if (G.f & G_DOSCRIPTLINKS) { + BPY_do_all_scripts(SCRIPT_RENDER); + /* avoid FRAMECHANGED slink event + * (should only be triggered in anims): */ + G.f &= ~G_DOSCRIPTLINKS; + slink_flag= 1; + } + RE_BlenderAnim(re, G.scene, frame, frame); + + if (slink_flag) { + G.f |= G_DOSCRIPTLINKS; + BPY_do_all_scripts(SCRIPT_POSTRENDER); + } } } else { printf("\nError: no blend loaded. cannot use '-f'.\n"); @@ -628,7 +643,14 @@ int main(int argc, char **argv) case 'a': if (G.scene) { Render *re= RE_NewRender(G.scene->id.name); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_RENDER); + RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_POSTRENDER); } else { printf("\nError: no blend loaded. cannot use '-a'.\n"); } |