From 4c0b33ef80efda5628883d6ca12e855dfe95d9e9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 20 Feb 2008 18:56:07 +0000 Subject: Python Bugfix A new file could have its Blender.Get("filename") return "" after undo'ing on an open file. Fix for own error with python sys.path, messed up game engine. --- source/blender/blenkernel/intern/blender.c | 4 ++-- source/blender/makesdna/DNA_scene_types.h | 4 +++- source/blender/python/BPY_interface.c | 6 +++--- source/blender/python/api2_2x/Blender.c | 4 ++-- source/blender/python/api2_2x/sceneRender.c | 11 +++++++---- source/blender/render/intern/source/pipeline.c | 2 +- source/blender/src/buttons_scene.c | 4 ++-- source/blender/src/previewrender.c | 2 -- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 8574cf00e8d..b3eeb884bfe 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -482,7 +482,7 @@ int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r) if (type_r) *((BlenFileType*)type_r)= bfd->type; - setup_app_data(bfd, ""); + setup_app_data(bfd, ""); } else { error("Loading failed: %s", BLO_bre_as_string(bre)); } @@ -504,7 +504,7 @@ int BKE_read_file_from_memfile(MemFile *memfile) bfd= BLO_read_from_memfile(G.sce, memfile, &bre); if (bfd) { - setup_app_data(bfd, ""); + setup_app_data(bfd, ""); } else { error("Loading failed: %s", BLO_bre_as_string(bre)); } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index f3e7ba66ae0..01b04435c58 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -575,7 +575,9 @@ typedef struct Scene { /* fbuf obsolete... */ #define R_FBUF 0x40000 /* threads obsolete... is there for old files, now use for autodetect threads */ -#define R_THREADS 0x80000 +#define R_THREADS 0x80000 + /* Use the same flag for autothreads */ +#define R_AUTO_THREADS 0x80000 #define R_SPEED 0x100000 #define R_SSS 0x200000 diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 02b65c3077d..9d28e8f9e38 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -377,7 +377,7 @@ void init_syspath( int first_time ) d = PyModule_GetDict( mod ); /* borrowed ref */ EXPP_dict_set_item_str( d, "executable", Py_BuildValue( "s", bprogname ) ); - if (first_time) { + if (bpy_orig_syspath_List == NULL) { /* backup the original sys.path to rebuild later */ PyObject *syspath = PyDict_GetItemString( d, "path" ); /* borrowed ref */ if (bpy_orig_syspath_List) { /* This should never happen but just incase, be nice */ @@ -401,12 +401,12 @@ void BPY_rebuild_syspath( void ) mod = PyImport_ImportModule( "sys" ); if (!mod) { - printf("error: could not import python sys module. some modules may not import."); + printf("error: could not import python sys module. some modules may not import.\n"); return; } if (!bpy_orig_syspath_List) { /* should never happen */ - printf("error refershing python path"); + printf("error refershing python path\n"); Py_DECREF(mod); return; } diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index b6ec761f219..b0f396943d9 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -341,10 +341,10 @@ static PyObject *Blender_Get( PyObject * self, PyObject * value ) else if( StringEqual( str, "endframe" ) ) ret = PyInt_FromLong( G.scene->r.efra ); else if( StringEqual( str, "filename" ) ) { - if ( strstr(G.main->name, ".B.blend") != 0) + if (!G.relbase_valid) ret = PyString_FromString(""); else - ret = PyString_FromString(G.main->name); + ret = PyString_FromString(G.sce); } else if( StringEqual( str, "homedir" ) ) { char *hdir = bpy_gethome(0); diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c index 2d73d4fc8b7..29fc018e16d 100644 --- a/source/blender/python/api2_2x/sceneRender.c +++ b/source/blender/python/api2_2x/sceneRender.c @@ -2089,7 +2089,7 @@ static int RenderData_setModeBit( BPy_RenderData* self, PyObject *value, #define MODE_MASK ( R_OSA | R_SHADOW | R_GAMMA | R_ENVMAP | R_EDGE | \ R_FIELDS | R_FIELDSTILL | R_RADIO | R_BORDER | R_PANORAMA | R_CROP | \ - R_ODDFIELD | R_MBLUR | R_RAYTRACE | R_THREADS ) + R_ODDFIELD | R_MBLUR | R_RAYTRACE | R_AUTO_THREADS ) static PyObject *RenderData_getMode( BPy_RenderData *self ) { @@ -2593,10 +2593,13 @@ static PyGetSetDef BPy_RenderData_getseters[] = { (getter)RenderData_getModeBit, (setter)RenderData_setModeBit, "Skip rendering existing image files", (void *)R_NO_OVERWRITE}, - + {"autoThreads", + (getter)RenderData_getModeBit, (setter)RenderData_setModeBit, + "Use system number of processors", + (void *)R_AUTO_THREADS}, /* R_GAUSS unused */ /* R_FBUF unused */ -/* R_THREADS unused */ +/* R_AUTO_THREADS unused */ {"threads", (getter)RenderData_getThreads, (setter)RenderData_setThreads, "Number of threads used to render", @@ -3718,7 +3721,7 @@ static PyObject *M_Render_ModesDict( void ) PyConstant_Insert( d, "ODDFIELD", PyInt_FromLong( R_ODDFIELD ) ); PyConstant_Insert( d, "MBLUR", PyInt_FromLong( R_MBLUR ) ); PyConstant_Insert( d, "RAYTRACING", PyInt_FromLong( R_RAYTRACE ) ); - PyConstant_Insert( d, "THREADS", PyInt_FromLong( R_THREADS ) ); + PyConstant_Insert( d, "AUTOTHREADS", PyInt_FromLong( R_AUTO_THREADS ) ); } return M; } diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 5de109a16f4..f537cbff259 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -1108,7 +1108,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, int winx, int winy /* we clip faces with a minimum of 2 pixel boundary outside of image border. see zbuf.c */ re->clipcrop= 1.0f + 2.0f/(float)(re->winx>re->winy?re->winy:re->winx); - if (rd->mode & R_THREADS || commandline_threads == 0) { /* Automatic threads */ + if (rd->mode & R_AUTO_THREADS || commandline_threads == 0) { /* Automatic threads */ re->r.threads = BLI_system_thread_count(); } else if(commandline_threads >= 1 && commandline_threads<=BLENDER_MAX_THREADS) { re->r.threads= commandline_threads; diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c index e3c3dcaf08d..da5f2817e4e 100644 --- a/source/blender/src/buttons_scene.c +++ b/source/blender/src/buttons_scene.c @@ -2023,8 +2023,8 @@ static void render_panel_output(void) uiBlockEndAlign(block); uiBlockBeginAlign(block); - uiDefIconButBitI(block, TOG, R_THREADS, B_REDR, ICON_AUTO, 10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatic threads from system"); - if (G.scene->r.mode & R_THREADS) { + uiDefIconButBitI(block, TOG, R_AUTO_THREADS, B_REDR, ICON_AUTO, 10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatically set the threads to the number of processors on the system"); + if (G.scene->r.mode & R_AUTO_THREADS) { char thread_str[16]; sprintf(thread_str, " Threads: %d", BLI_system_thread_count()); uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, ""); diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index 00ae72d95d1..a8ecd0d770b 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -264,8 +264,6 @@ static Scene *preview_prepare_scene(RenderInfo *ri, int id_type, ID *id, int pr_ sce= pr_main->scene.first; if(sce) { - - // sce->r.mode |= G.scene->r.mode & R_THREADS; /* this flag tells render to not execute depsgraph or ipos etc */ sce->r.scemode |= R_PREVIEWBUTS; /* set world always back, is used now */ -- cgit v1.2.3