while. This may not fix all cases but should at least solve the issue when
rendering with cycles.
The cause was a race condition on C->data.recursion, with multiple threads
accessing context at the same time. Cycles itself does not access context
from the render thread, but the bpy api would do a context update for any
callback in case e.g. a new file got loaded. Disabled that now in non-main
threads.
The ideal solution would be to not allow any context access at all from threads
but that's not so simple to implement, especially not this close to release.
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
+#include "BLI_threads.h"
#include "BKE_context.h"
#include "BKE_text.h"
/* use for updating while a python script runs - in case of file load */
void bpy_context_update(bContext *C)
{
+ /* don't do this from a non-main (e.g. render) thread, it can cause a race
+ condition on C->data.recursion. ideal solution would be to disable
+ context entirely from non-main threads, but that's more complicated */
+ if(!BLI_thread_is_main())
+ return;
+
BPy_SetContext(C);
bpy_import_main_set(CTX_data_main(C));
BPY_modules_update(C); /* can give really bad results if this isn't here */