diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-02-13 02:13:45 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-02-13 02:14:57 +0400 |
commit | e43c3ad88af70617f7708a82c0189f202681ac67 (patch) | |
tree | 996e3af3e853c5c1b9697cef9d611077fcccecd3 /intern/cycles/blender | |
parent | 9cc380e02668a7ff4c28e9541cfe84fdb1ff47ba (diff) |
Fix issue in recent bugfix, did not work with multiple sessions (preview render).
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_object.cpp | 10 | ||||
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 38 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 23 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.h | 4 | ||||
-rw-r--r-- | intern/cycles/blender/blender_sync.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/blender/blender_sync.h | 4 | ||||
-rw-r--r-- | intern/cycles/blender/blender_util.h | 4 |
7 files changed, 48 insertions, 39 deletions
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index c8a2f080bba..cc52717fdb6 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -516,7 +516,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) mesh_motion_synced.clear(); } -void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override) +void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state) { if(scene->need_motion() == Scene::MOTION_NONE) return; @@ -535,9 +535,9 @@ void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override) /* we need to set the python thread state again because this * function assumes it is being executed from python and will * try to save the thread state */ - python_thread_state_restore(); + python_thread_state_restore(python_thread_state); b_scene.frame_set(frame + motion, 0.0f); - python_thread_state_save(); + python_thread_state_save(python_thread_state); /* camera object */ if(b_cam) @@ -550,9 +550,9 @@ void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override) /* we need to set the python thread state again because this * function assumes it is being executed from python and will * try to save the thread state */ - python_thread_state_restore(); + python_thread_state_restore(python_thread_state); b_scene.frame_set(frame, 0.0f); - python_thread_state_save(); + python_thread_state_save(python_thread_state); /* tag camera for motion update */ if(scene->camera->motion_modified(prevcam)) diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 6c9f1dc080f..e08b7980e78 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -35,17 +35,15 @@ CCL_NAMESPACE_BEGIN -static PyThreadState *python_thread_state = NULL; - -void python_thread_state_save() +void python_thread_state_save(void **python_thread_state) { - python_thread_state = PyEval_SaveThread(); + *python_thread_state = (void*)PyEval_SaveThread(); } -void python_thread_state_restore() +void python_thread_state_restore(void **python_thread_state) { - PyEval_RestoreThread(python_thread_state); - python_thread_state = NULL; + PyEval_RestoreThread((PyThreadState*)*python_thread_state); + *python_thread_state = NULL; } static PyObject *init_func(PyObject *self, PyObject *args) @@ -100,8 +98,6 @@ static PyObject *create_func(PyObject *self, PyObject *args) /* create session */ BlenderSession *session; - python_thread_state_save(); - if(rv3d) { /* interactive viewport session */ int width = region.width(); @@ -122,7 +118,11 @@ static PyObject *create_func(PyObject *self, PyObject *args) session = new BlenderSession(engine, userpref, data, scene); } - python_thread_state_restore(); + python_thread_state_save(&session->python_thread_state); + + session->create(); + + python_thread_state_restore(&session->python_thread_state); return PyLong_FromVoidPtr(session); } @@ -136,12 +136,13 @@ static PyObject *free_func(PyObject *self, PyObject *value) static PyObject *render_func(PyObject *self, PyObject *value) { - python_thread_state_save(); - BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value); + + python_thread_state_save(&session->python_thread_state); + session->render(); - python_thread_state_restore(); + python_thread_state_restore(&session->python_thread_state); Py_RETURN_NONE; } @@ -183,23 +184,24 @@ static PyObject *reset_func(PyObject *self, PyObject *args) RNA_id_pointer_create((ID*)PyLong_AsVoidPtr(pyscene), &sceneptr); BL::Scene b_scene(sceneptr); - python_thread_state_save(); + python_thread_state_save(&session->python_thread_state); session->reset_session(b_data, b_scene); - python_thread_state_restore(); + python_thread_state_restore(&session->python_thread_state); Py_RETURN_NONE; } static PyObject *sync_func(PyObject *self, PyObject *value) { - python_thread_state_save(); - BlenderSession *session = (BlenderSession*)PyLong_AsVoidPtr(value); + + python_thread_state_save(&session->python_thread_state); + session->synchronize(); - python_thread_state_restore(); + python_thread_state_restore(&session->python_thread_state); Py_RETURN_NONE; } diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 1d3c49b519c..ef578493901 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -40,7 +40,7 @@ CCL_NAMESPACE_BEGIN BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_, BL::BlendData b_data_, BL::Scene b_scene_) : b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_render(b_engine_.render()), b_scene(b_scene_), - b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL) + b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL), python_thread_state(NULL) { /* offline render */ @@ -50,15 +50,13 @@ BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b background = true; last_redraw_time = 0.0; start_resize_time = 0.0; - - create_session(); } BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_, BL::BlendData b_data_, BL::Scene b_scene_, BL::SpaceView3D b_v3d_, BL::RegionView3D b_rv3d_, int width_, int height_) : b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_render(b_scene_.render()), b_scene(b_scene_), - b_v3d(b_v3d_), b_rv3d(b_rv3d_) + b_v3d(b_v3d_), b_rv3d(b_rv3d_), python_thread_state(NULL) { /* 3d view render */ @@ -67,9 +65,6 @@ BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b background = false; last_redraw_time = 0.0; start_resize_time = 0.0; - - create_session(); - session->start(); } BlenderSession::~BlenderSession() @@ -77,6 +72,14 @@ BlenderSession::~BlenderSession() free_session(); } +void BlenderSession::create() +{ + create_session(); + + if(b_v3d) + session->start(); +} + void BlenderSession::create_session() { SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background); @@ -102,7 +105,7 @@ void BlenderSession::create_session() if(b_v3d) { /* full data sync */ - sync->sync_data(b_v3d, b_engine.camera_override()); + sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state); sync->sync_view(b_v3d, b_rv3d, width, height); } else { @@ -389,7 +392,7 @@ void BlenderSession::render() /* update scene */ sync->sync_camera(b_render, b_engine.camera_override(), width, height); - sync->sync_data(b_v3d, b_engine.camera_override(), b_rlay_name.c_str()); + sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state, b_rlay_name.c_str()); /* update number of samples per layer */ int samples = sync->get_layer_samples(); @@ -506,7 +509,7 @@ void BlenderSession::synchronize() } /* data and camera synchronize */ - sync->sync_data(b_v3d, b_engine.camera_override()); + sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state); if(b_rv3d) sync->sync_view(b_v3d, b_rv3d, width, height); diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h index 86b22165084..0568fb291d0 100644 --- a/intern/cycles/blender/blender_session.h +++ b/intern/cycles/blender/blender_session.h @@ -40,6 +40,8 @@ public: ~BlenderSession(); + void create(); + /* session */ void create_session(); void free_session(); @@ -90,6 +92,8 @@ public: int width, height; double start_resize_time; + void *python_thread_state; + protected: void do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only); void do_write_update_render_tile(RenderTile& rtile, bool do_update_only); diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index d21ffdec0d1..8e2197a2aa6 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -135,7 +135,7 @@ bool BlenderSync::sync_recalc() return recalc; } -void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, const char *layer) +void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state, const char *layer) { sync_render_layers(b_v3d, layer); sync_integrator(); @@ -143,7 +143,7 @@ void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, const sync_shaders(); sync_curve_settings(); sync_objects(b_v3d); - sync_motion(b_v3d, b_override); + sync_motion(b_v3d, b_override, python_thread_state); } /* Integrator */ diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 3d2a3ae5aac..205761ad302 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -53,7 +53,7 @@ public: /* sync */ bool sync_recalc(); - void sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, const char *layer = 0); + void sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state, const char *layer = 0); void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer); void sync_integrator(); void sync_camera(BL::RenderSettings b_render, BL::Object b_override, int width, int height); @@ -72,7 +72,7 @@ private: void sync_lamps(bool update_all); void sync_materials(bool update_all); void sync_objects(BL::SpaceView3D b_v3d, int motion = 0); - void sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override); + void sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state); void sync_film(); void sync_view(); void sync_world(bool update_all); diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index c9048cd8a28..58e523d7fc2 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -37,8 +37,8 @@ float *BKE_image_get_float_pixels_for_frame(void *image, int frame); CCL_NAMESPACE_BEGIN -void python_thread_state_save(); -void python_thread_state_restore(); +void python_thread_state_save(void **python_thread_state); +void python_thread_state_restore(void **python_thread_state); static inline BL::Mesh object_to_mesh(BL::BlendData data, BL::Object object, BL::Scene scene, bool apply_modifiers, bool render, bool calc_undeformed) { |