== 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
This commit is contained in:
Willian Padovani Germano 2008-07-26 22:00:26 +00:00
parent 70ce017777
commit 8a295553f7
2 changed files with 54 additions and 6 deletions

View File

@ -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;
}

View File

@ -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");
}