forked from bartvdbraak/blender
dont use a thread for baking in background mode, its not really any advantage since it starts a single thread that runs a loop.
This commit is contained in:
parent
a6826584ef
commit
88743740b8
@ -2366,8 +2366,12 @@ typedef struct {
|
||||
static void *ptcache_make_cache_thread(void *ptr) {
|
||||
ptcache_make_cache_data *data = (ptcache_make_cache_data*)ptr;
|
||||
|
||||
for(; (*data->cfra_ptr <= data->endframe) && !data->break_operation; *data->cfra_ptr+=data->step)
|
||||
for(; (*data->cfra_ptr <= data->endframe) && !data->break_operation; *data->cfra_ptr+=data->step) {
|
||||
scene_update_for_newframe(data->scene, data->scene->lay);
|
||||
if(G.background) {
|
||||
printf("bake: frame %d :: %d\n", (int)*data->cfra_ptr, data->endframe);
|
||||
}
|
||||
}
|
||||
|
||||
data->thread_ended = TRUE;
|
||||
return NULL;
|
||||
@ -2489,36 +2493,40 @@ void BKE_ptcache_make_cache(PTCacheBaker* baker)
|
||||
thread_data.thread_ended = FALSE;
|
||||
old_progress = -1;
|
||||
|
||||
BLI_init_threads(&threads, ptcache_make_cache_thread, 1);
|
||||
BLI_insert_thread(&threads, (void*)&thread_data);
|
||||
|
||||
while (thread_data.thread_ended == FALSE) {
|
||||
|
||||
if(bake)
|
||||
progress = (int)(100.0f * (float)(CFRA - startframe)/(float)(thread_data.endframe-startframe));
|
||||
else
|
||||
progress = CFRA;
|
||||
|
||||
/* NOTE: baking should not redraw whole ui as this slows things down */
|
||||
if ((baker->progressbar) && (progress != old_progress)) {
|
||||
baker->progressbar(baker->progresscontext, progress);
|
||||
old_progress = progress;
|
||||
}
|
||||
|
||||
/* Delay to lessen CPU load from UI thread */
|
||||
PIL_sleep_ms(200);
|
||||
|
||||
/* NOTE: breaking baking should leave calculated frames in cache, not clear it */
|
||||
if(blender_test_break() && !thread_data.break_operation) {
|
||||
thread_data.break_operation = TRUE;
|
||||
if (baker->progressend)
|
||||
baker->progressend(baker->progresscontext);
|
||||
WM_cursor_wait(1);
|
||||
}
|
||||
if(G.background) {
|
||||
ptcache_make_cache_thread((void*)&thread_data);
|
||||
}
|
||||
else {
|
||||
BLI_init_threads(&threads, ptcache_make_cache_thread, 1);
|
||||
BLI_insert_thread(&threads, (void*)&thread_data);
|
||||
|
||||
while (thread_data.thread_ended == FALSE) {
|
||||
|
||||
if(bake)
|
||||
progress = (int)(100.0f * (float)(CFRA - startframe)/(float)(thread_data.endframe-startframe));
|
||||
else
|
||||
progress = CFRA;
|
||||
|
||||
/* NOTE: baking should not redraw whole ui as this slows things down */
|
||||
if ((baker->progressbar) && (progress != old_progress)) {
|
||||
baker->progressbar(baker->progresscontext, progress);
|
||||
old_progress = progress;
|
||||
}
|
||||
|
||||
/* Delay to lessen CPU load from UI thread */
|
||||
PIL_sleep_ms(200);
|
||||
|
||||
/* NOTE: breaking baking should leave calculated frames in cache, not clear it */
|
||||
if(blender_test_break() && !thread_data.break_operation) {
|
||||
thread_data.break_operation = TRUE;
|
||||
if (baker->progressend)
|
||||
baker->progressend(baker->progresscontext);
|
||||
WM_cursor_wait(1);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_end_threads(&threads);
|
||||
|
||||
}
|
||||
/* clear baking flag */
|
||||
if(pid) {
|
||||
cache->flag &= ~(PTCACHE_BAKING|PTCACHE_REDO_NEEDED);
|
||||
|
@ -109,7 +109,11 @@ static int bpy_pydriver_create_dict(void)
|
||||
*/
|
||||
void BPY_pydriver_update(void)
|
||||
{
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyGILState_STATE gilstate;
|
||||
int use_gil= 1; // (PyThreadState_Get()==NULL);
|
||||
|
||||
if(use_gil)
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */
|
||||
PyDict_Clear(bpy_pydriver_Dict);
|
||||
@ -117,7 +121,8 @@ void BPY_pydriver_update(void)
|
||||
bpy_pydriver_Dict = NULL;
|
||||
}
|
||||
|
||||
PyGILState_Release(gilstate);
|
||||
if(use_gil)
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -143,6 +148,10 @@ static float pydriver_error(ChannelDriver *driver)
|
||||
|
||||
/* This evals py driver expressions, 'expr' is a Python expression that
|
||||
* should evaluate to a float number, which is returned.
|
||||
*
|
||||
* note: PyGILState_Ensure() isnt always called because python can call the
|
||||
* bake operator which intern starts a thread which calls scene update which
|
||||
* does a driver update. to avoid a deadlock check PyThreadState_Get() if PyGILState_Ensure() is needed.
|
||||
*/
|
||||
float BPY_pydriver_eval (ChannelDriver *driver)
|
||||
{
|
||||
@ -151,6 +160,7 @@ float BPY_pydriver_eval (ChannelDriver *driver)
|
||||
PyObject *expr_vars; /* speed up by pre-hashing string & avoids re-converting unicode strings for every execution */
|
||||
PyObject *expr_code;
|
||||
PyGILState_STATE gilstate;
|
||||
int use_gil;
|
||||
|
||||
DriverVar *dvar;
|
||||
double result = 0.0; /* default return */
|
||||
@ -168,13 +178,17 @@ float BPY_pydriver_eval (ChannelDriver *driver)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
gilstate = PyGILState_Ensure();
|
||||
use_gil= 1; //(PyThreadState_Get()==NULL);
|
||||
|
||||
if(use_gil)
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
/* init global dictionary for py-driver evaluation settings */
|
||||
if (!bpy_pydriver_Dict) {
|
||||
if (bpy_pydriver_create_dict() != 0) {
|
||||
fprintf(stderr, "Pydriver error: couldn't create Python dictionary");
|
||||
PyGILState_Release(gilstate);
|
||||
if(use_gil)
|
||||
PyGILState_Release(gilstate);
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@ -269,7 +283,8 @@ float BPY_pydriver_eval (ChannelDriver *driver)
|
||||
Py_DECREF(retval);
|
||||
}
|
||||
|
||||
PyGILState_Release(gilstate);
|
||||
if(use_gil)
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
if(finite(result)) {
|
||||
return (float)result;
|
||||
|
Loading…
Reference in New Issue
Block a user