From 2ed7a66653c9c94cb47064cb12092c2e81331b9b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 28 Oct 2011 13:07:11 +0000 Subject: [PATCH 1/7] BLI_string: Adding the BLI_strtok_r function, which mimics stdlib strtok_r (unavailable on some systems). It allows to iterate over a string, returning an new element each time, using a char as separator. See BLI_String.h's comments for more info and an example. Needed by the UI template list patch following! --- source/blender/blenlib/BLI_string.h | 22 +++++++++++++++++++ source/blender/blenlib/intern/string.c | 29 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 0cdb573c4c6..9a7fa521af1 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -133,6 +133,28 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len); int BLI_natstrcmp(const char *s1, const char *s2); size_t BLI_strnlen(const char *str, size_t maxlen); + /** + * Split str on the first occurence of delimiter, returns the first + * part as a mallocN'd string, and stores the second part into + * ctx (also mallocN'd). + * If str is NULL, split on ctx instead. + * This allows to iterate over this "generator" function: + * + * char *ctx = NULL; + * char *res = NULL; + * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) { + * printf(res); + * MEM_freeN(res); + * } + * + * @param str The string to be split. + * @param delimiter The char used to split str apart. + * @param ctx The "context" string. It’s a pointer inside the org passed @str, + * so it has no specific mem management. + * @retval Returns the mallocN'd first element from split str (or ctx). + */ +char *BLI_strtok_r(char *str, const char *delimiter, char **ctx); + void BLI_timestr(double _time, char *str); /* time var is global */ void BLI_ascii_strtolower(char *str, int len); diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 3a66425a5de..3ec84e0b593 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -375,6 +375,35 @@ int BLI_natstrcmp(const char *s1, const char *s2) return 0; } +/* As unfortunately strtok_r is not available everywhere... */ +char *BLI_strtok_r(char *str, const char *delimiter, char **ctx) +{ + char *cut = NULL, *ret = NULL; + char *split = str ? str : *ctx; + + if(!split) { + return ret; + } + + cut = strchr(split, *delimiter); + if(cut) { + size_t len_ret = cut - split; + size_t len_ctx = strlen(split) - len_ret - 1; + ret = BLI_strdupn(split, len_ret); + if(len_ctx > 0) { + *ctx = split+len_ret+1; + } + else { + *ctx = NULL; + } + } + else { + ret = BLI_strdup(split); + *ctx = NULL; + } + return ret; +} + void BLI_timestr(double _time, char *str) { /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ From 7627a742ab6e630522186b04a71fa40533d87db2 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 28 Oct 2011 13:09:43 +0000 Subject: [PATCH 2/7] UI list template: committing patch [#26629]. This adds the ability (esp. for py scripts) to add some controls for each list element. See http://wiki.blender.org/index.php/User:Mont29/UI_Template_List_Enhancement for details. --- source/blender/editors/include/UI_interface.h | 2 +- .../editors/interface/interface_templates.c | 52 +++++++++++++++++-- source/blender/makesrna/intern/rna_ui_api.c | 3 ++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index a7ced565403..cb18ea37ffc 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -749,7 +749,7 @@ void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *te void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C); void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr); -void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, int rows, int maxrows, int type); +void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, const char *prop_list, int rows, int maxrows, int type); /* items */ void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index b816d1a8f9c..e714d0bbc17 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2059,7 +2059,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int return rnaicon; } -static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop) +static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list) { uiBlock *block= uiLayoutGetBlock(layout); uiBut *but; @@ -2164,6 +2164,52 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe /* nothing else special to do... */ uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */ } + /* There is a last chance to display custom controls (in addition to the name/label): + * If the given item property group features a string property named as prop_list, + * this tries to add controls for all properties of the item listed in that string property. + * (colon-separated names). + * + * This is especially useful for python. E.g., if you list a collection of this property + * group: + * + * class TestPropertyGroup(bpy.types.PropertyGroup): + * bool = BoolProperty(default=False) + * integer = IntProperty() + * string = StringProperty() + * + * # A string of all identifiers (colon-separated) which property’s controls should be + * # displayed in a template_list. + * template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"}) + * + * … you’ll get a numfield for the integer prop, a check box for the bool prop, and a textfield + * for the string prop, after the name of each item of the collection. + */ + else if (prop_list) { + PropertyRNA *prop_ctrls; + row = uiLayoutRow(sub, 1); + uiItemL(row, name, icon); + + /* XXX: Check, as sometimes we get an itemptr looking like + * {id = {data = 0x0}, type = 0x0, data = 0x0} + * which would obviously produce a sigsev… */ + if (itemptr->type) { + /* If the special property is set for the item, and it is a collection… */ + prop_ctrls = RNA_struct_find_property(itemptr, prop_list); + if(prop_ctrls) { + if(RNA_property_type(prop_ctrls) == PROP_STRING) { + char *prop_names = RNA_property_string_get_alloc(itemptr, prop_ctrls, NULL, 0, NULL); + char *id = NULL; + char *ctx = NULL; + for(id = BLI_strtok_r(prop_names, ":", &ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) { + uiItemR(row, itemptr, id, 0, NULL, 0); + MEM_freeN(id); + } + MEM_freeN(prop_names); + } + } + } + } + else uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */ @@ -2172,7 +2218,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe MEM_freeN(namebuf); } -void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, int rows, int maxrows, int listtype) +void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype) { //Scene *scene= CTX_data_scene(C); PropertyRNA *prop= NULL, *activeprop; @@ -2326,7 +2372,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * /* create list items */ RNA_PROP_BEGIN(ptr, itemptr, prop) { if(i >= pa->list_scroll && ilist_scroll+items) - list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop); + list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop, prop_list); i++; } diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 659346974fa..4862b5224ab 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -408,6 +408,9 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL); parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of property in data, for the active element"); RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "prop_list", "", 0, "", + "Identifier of a string property in each data member, specifying which " + "of its properties should have a widget displayed in its row."); RNA_def_int(func, "rows", 5, 0, INT_MAX, "", "Number of rows to display", 0, INT_MAX); RNA_def_int(func, "maxrows", 5, 0, INT_MAX, "", "Maximum number of rows to display", 0, INT_MAX); RNA_def_enum(func, "type", list_type_items, 0, "Type", "Type of list to use"); From ed77c356fc1c323cef306fef2e7af03fd67a6871 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 28 Oct 2011 16:57:06 +0000 Subject: [PATCH 3/7] Fix: OpenGL renders on graphics cards which do not support non-power-of-two textures were stretched and the wrong size. --- source/blender/editors/render/render_opengl.c | 8 ++--- .../editors/space_view3d/view3d_draw.c | 6 ++-- source/blender/gpu/GPU_extensions.h | 5 ++-- source/blender/gpu/intern/gpu_extensions.c | 29 +++++++++++-------- source/blender/gpu/intern/gpu_material.c | 3 +- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index feeb2fefca7..fa764e6eefc 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -154,7 +154,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender) if((scene->r.mode & R_OSA) == 0) { ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat); - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, rr->rectf); + GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, rr->rectf); } else { /* simple accumulation, less hassle then FSAA FBO's */ @@ -167,7 +167,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender) /* first sample buffer, also initializes 'rv3d->persmat' */ ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat); - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_buffer); + GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_buffer); /* skip the first sample */ for(j=1; j < SAMPLES; j++) { @@ -175,7 +175,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender) window_translate_m4(winmat_jitter, rv3d->persmat, jit_ofs[j][0] / sizex, jit_ofs[j][1] / sizey); ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter); - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_tmp); + GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_tmp); add_vn_vn(accum_buffer, accum_tmp, sizex*sizey*sizeof(float)); } @@ -278,7 +278,7 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op) sizey= (scene->r.size*scene->r.ysch)/100; /* corrects render size with actual size, not every card supports non-power-of-two dimensions */ - ofs= GPU_offscreen_create(&sizex, &sizey, err_out); + ofs= GPU_offscreen_create(sizex, sizey, err_out); if(!ofs) { BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL offscreen buffer, %s", err_out); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 20b1df6ef2c..32e553262e2 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -2379,7 +2379,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in glPushAttrib(GL_LIGHTING_BIT); /* bind */ - ofs= GPU_offscreen_create(&sizex, &sizey, err_out); + ofs= GPU_offscreen_create(sizex, sizey, err_out); if(ofs == NULL) return NULL; @@ -2403,9 +2403,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in ibuf= IMB_allocImBuf(sizex, sizey, 32, flag); if(ibuf->rect_float) - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, ibuf->rect_float); + GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float); else if(ibuf->rect) - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect); //if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) // BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4); diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index 965f317aa50..3fff79390e3 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -136,7 +136,7 @@ int GPU_texture_opengl_bindcode(GPUTexture *tex); GPUFrameBuffer *GPU_framebuffer_create(void); int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]); void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex); -void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex); +void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h); void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex); void GPU_framebuffer_free(GPUFrameBuffer *fb); @@ -146,10 +146,11 @@ void GPU_framebuffer_restore(void); - wrapper around framebuffer and texture for simple offscreen drawing - changes size if graphics card can't support it */ -GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]); +GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]); void GPU_offscreen_free(GPUOffScreen *ofs); void GPU_offscreen_bind(GPUOffScreen *ofs); void GPU_offscreen_unbind(GPUOffScreen *ofs); +void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels); /* GPU Shader - only for fragment shaders now diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index 6189062a855..e1a89daf7e2 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -790,7 +790,7 @@ void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex) tex->fb = NULL; } -void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex) +void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex, int w, int h) { /* push attributes */ glPushAttrib(GL_ENABLE_BIT); @@ -801,7 +801,7 @@ void GPU_framebuffer_texture_bind(GPUFrameBuffer *UNUSED(fb), GPUTexture *tex) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, tex->fb->object); /* push matrices and set default viewport and matrix */ - glViewport(0, 0, tex->w, tex->h); + glViewport(0, 0, w, h); GG.currentfb = tex->fb->object; glMatrixMode(GL_PROJECTION); @@ -859,13 +859,19 @@ struct GPUOffScreen { GPUFrameBuffer *fb; GPUTexture *color; GPUTexture *depth; + + /* requested width/height, may be smaller than actual texture size due + to missing non-power of two support, so we compensate for that */ + int w, h; }; -GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]) +GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]) { GPUOffScreen *ofs; ofs= MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen"); + ofs->w= width; + ofs->h= height; ofs->fb = GPU_framebuffer_create(); if(!ofs->fb) { @@ -873,24 +879,18 @@ GPUOffScreen *GPU_offscreen_create(int *width, int *height, char err_out[256]) return NULL; } - ofs->depth = GPU_texture_create_depth(*width, *height, err_out); + ofs->depth = GPU_texture_create_depth(width, height, err_out); if(!ofs->depth) { GPU_offscreen_free(ofs); return NULL; } - if(*width!=ofs->depth->w || *height!=ofs->depth->h) { - *width= ofs->depth->w; - *height= ofs->depth->h; - printf("Offscreen size differs from given size!\n"); - } - if(!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, err_out)) { GPU_offscreen_free(ofs); return NULL; } - ofs->color = GPU_texture_create_2D(*width, *height, NULL, err_out); + ofs->color = GPU_texture_create_2D(width, height, NULL, err_out); if(!ofs->color) { GPU_offscreen_free(ofs); return NULL; @@ -921,7 +921,7 @@ void GPU_offscreen_free(GPUOffScreen *ofs) void GPU_offscreen_bind(GPUOffScreen *ofs) { glDisable(GL_SCISSOR_TEST); - GPU_framebuffer_texture_bind(ofs->fb, ofs->color); + GPU_framebuffer_texture_bind(ofs->fb, ofs->color, ofs->w, ofs->h); } void GPU_offscreen_unbind(GPUOffScreen *ofs) @@ -931,6 +931,11 @@ void GPU_offscreen_unbind(GPUOffScreen *ofs) glEnable(GL_SCISSOR_TEST); } +void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels) +{ + glReadPixels(0, 0, ofs->w, ofs->h, GL_RGBA, type, pixels); +} + /* GPUShader */ struct GPUShader { diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index d0f834977c8..26c08f6cae5 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1661,7 +1661,8 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize /* opengl */ glDisable(GL_SCISSOR_TEST); - GPU_framebuffer_texture_bind(lamp->fb, lamp->tex); + GPU_framebuffer_texture_bind(lamp->fb, lamp->tex, + GPU_texture_opengl_width(lamp->tex), GPU_texture_opengl_height(lamp->tex)); /* set matrices */ copy_m4_m4(viewmat, lamp->viewmat); From 1e4be0a4bf9b16aa74ced29fcac8aef56195bbe8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 29 Oct 2011 08:18:42 +0000 Subject: [PATCH 4/7] replace BLI_strtok_r from r41337 with lighter method that doesnt alloc for template_list --- source/blender/blenlib/BLI_string.h | 23 -------------- source/blender/blenlib/intern/bpath.c | 3 +- source/blender/blenlib/intern/string.c | 29 ------------------ .../editors/interface/interface_templates.c | 30 ++++++++++--------- 4 files changed, 17 insertions(+), 68 deletions(-) diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 9a7fa521af1..46389a9259e 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -132,29 +132,6 @@ int BLI_strcasecmp(const char *s1, const char *s2); int BLI_strncasecmp(const char *s1, const char *s2, size_t len); int BLI_natstrcmp(const char *s1, const char *s2); size_t BLI_strnlen(const char *str, size_t maxlen); - - /** - * Split str on the first occurence of delimiter, returns the first - * part as a mallocN'd string, and stores the second part into - * ctx (also mallocN'd). - * If str is NULL, split on ctx instead. - * This allows to iterate over this "generator" function: - * - * char *ctx = NULL; - * char *res = NULL; - * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) { - * printf(res); - * MEM_freeN(res); - * } - * - * @param str The string to be split. - * @param delimiter The char used to split str apart. - * @param ctx The "context" string. It’s a pointer inside the org passed @str, - * so it has no specific mem management. - * @retval Returns the mallocN'd first element from split str (or ctx). - */ -char *BLI_strtok_r(char *str, const char *delimiter, char **ctx); - void BLI_timestr(double _time, char *str); /* time var is global */ void BLI_ascii_strtolower(char *str, int len); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index e42e02fb24f..b7fe7ef5efd 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -325,8 +325,7 @@ static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], char path_file } if (visit_cb(userdata, path_dst, (const char *)path_src)) { - BLI_split_dirfile(path_dst, path_dir, path_file, - sizeof(path_dir), sizeof(path_file)); + BLI_split_dirfile(path_dst, path_dir, path_file, FILE_MAXDIR, FILE_MAXFILE); return TRUE; } else { diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 3ec84e0b593..3a66425a5de 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -375,35 +375,6 @@ int BLI_natstrcmp(const char *s1, const char *s2) return 0; } -/* As unfortunately strtok_r is not available everywhere... */ -char *BLI_strtok_r(char *str, const char *delimiter, char **ctx) -{ - char *cut = NULL, *ret = NULL; - char *split = str ? str : *ctx; - - if(!split) { - return ret; - } - - cut = strchr(split, *delimiter); - if(cut) { - size_t len_ret = cut - split; - size_t len_ctx = strlen(split) - len_ret - 1; - ret = BLI_strdupn(split, len_ret); - if(len_ctx > 0) { - *ctx = split+len_ret+1; - } - else { - *ctx = NULL; - } - } - else { - ret = BLI_strdup(split); - *ctx = NULL; - } - return ret; -} - void BLI_timestr(double _time, char *str) { /* format 00:00:00.00 (hr:min:sec) string has to be 12 long */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index e714d0bbc17..19d22a432dc 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2059,7 +2059,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int return rnaicon; } -static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list) +static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list_id) { uiBlock *block= uiLayoutGetBlock(layout); uiBut *but; @@ -2184,8 +2184,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe * … you’ll get a numfield for the integer prop, a check box for the bool prop, and a textfield * for the string prop, after the name of each item of the collection. */ - else if (prop_list) { - PropertyRNA *prop_ctrls; + else if (prop_list_id) { row = uiLayoutRow(sub, 1); uiItemL(row, name, icon); @@ -2194,18 +2193,21 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe * which would obviously produce a sigsev… */ if (itemptr->type) { /* If the special property is set for the item, and it is a collection… */ - prop_ctrls = RNA_struct_find_property(itemptr, prop_list); - if(prop_ctrls) { - if(RNA_property_type(prop_ctrls) == PROP_STRING) { - char *prop_names = RNA_property_string_get_alloc(itemptr, prop_ctrls, NULL, 0, NULL); - char *id = NULL; - char *ctx = NULL; - for(id = BLI_strtok_r(prop_names, ":", &ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) { - uiItemR(row, itemptr, id, 0, NULL, 0); - MEM_freeN(id); - } - MEM_freeN(prop_names); + PropertyRNA *prop_list= RNA_struct_find_property(itemptr, prop_list_id); + + if(prop_list && RNA_property_type(prop_list) == PROP_STRING) { + int prop_names_len; + char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len); + char *prop_names_end= prop_names + prop_names_len; + char *id= prop_names; + char *id_next; + while (id < prop_names_end) { + if ((id_next= strchr(id, ':'))) *id_next++= '\0'; + else id_next= prop_names_end; + uiItemR(row, itemptr, id, 0, NULL, 0); + id= id_next; } + MEM_freeN(prop_names); } } } From e28c2ce753fbbcd26f5f22780f521e3ea85c060f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 29 Oct 2011 11:15:12 +0000 Subject: [PATCH 5/7] bug from revision 2!, error noticed kjym3 on IRC, buffer overrun on lbarray, was 30 but 39 items beting accessed, surprising this didnt crash earlier. --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index df5ed5a050c..f0f5ab283a6 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2264,7 +2264,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) static void write_libraries(WriteData *wd, Main *main) { - ListBase *lbarray[30]; + ListBase *lbarray[MAX_LIBARRAY]; ID *id; int a, tot, foundone; From 15bd96efeb77cf33215613a53059f01db7242b31 Mon Sep 17 00:00:00 2001 From: Andrew Wiggin Date: Sat, 29 Oct 2011 16:14:38 +0000 Subject: [PATCH 6/7] Fix RelWithDebInfo build. RelWithDebInfo sets the library path to only include release libraries (e.g. python32.lib) but defining _DEBUG when #include'ing python headers inserts a linker directive to require for python32_d.lib. Additionally, RelWithDebInfo should be different from release build in that it builds debugger symbols (.PDBs), it should not have asserts and other debug code. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7631b24f7cd..3fd5f3ef441 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ set(CMAKE_BUILD_TYPE_INIT "Release") set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG _DEBUG) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE NDEBUG) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL NDEBUG) -set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO DEBUG _DEBUG) +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO NDEBUG) #----------------------------------------------------------------------------- From f837b46a2b561293660a0edf9d4de5ff16922f42 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 29 Oct 2011 23:56:07 +0000 Subject: [PATCH 7/7] Modifier compilation tweaks (Blender conference commit) * Fluid compilation: Inverse the compile flag from DISABLE_ELBEEM to WITH_MOD_FLUID for consistency. (scons/cmake) * Use WITH_BF_FLUID in your user config (scons) * Add support for scons to disable build with Decimate and Boolean modifier. (WITH_BF_DECIMATE and WITH_BF_BOOLEAN) --- SConstruct | 10 ++++++---- build_files/scons/tools/btools.py | 8 ++++++-- intern/SConscript | 2 +- source/blender/blenkernel/CMakeLists.txt | 4 ++-- source/blender/blenkernel/SConscript | 4 ++-- source/blender/blenkernel/intern/effect.c | 4 ++-- source/blender/blenkernel/intern/particle_system.c | 8 ++++---- source/blender/editors/physics/CMakeLists.txt | 4 ++-- source/blender/editors/physics/physics_fluid.c | 6 +++--- source/blender/makesrna/intern/CMakeLists.txt | 4 ++-- source/blender/makesrna/intern/rna_fluidsim.c | 4 ++-- source/blender/modifiers/CMakeLists.txt | 4 ++-- source/blender/modifiers/SConscript | 12 +++++++----- source/blender/modifiers/intern/MOD_fluidsim_util.c | 11 ++++++----- 14 files changed, 47 insertions(+), 38 deletions(-) diff --git a/SConstruct b/SConstruct index 93787cdddce..16ce8ca4b32 100644 --- a/SConstruct +++ b/SConstruct @@ -253,7 +253,9 @@ if 'blenderlite' in B.targets: target_env_defs['WITH_BF_BULLET'] = False target_env_defs['WITH_BF_BINRELOC'] = False target_env_defs['BF_BUILDINFO'] = False - target_env_defs['BF_NO_ELBEEM'] = True + target_env_defs['WITH_BF_FLUID'] = False + target_env_defs['WITH_BF_DECIMATE'] = False + target_env_defs['WITH_BF_BOOLEAN'] = False target_env_defs['WITH_BF_PYTHON'] = False target_env_defs['WITH_BF_3DMOUSE'] = False @@ -323,9 +325,9 @@ if 'blenderplayer' in B.targets: if 'blendernogame' in B.targets: env['WITH_BF_GAMEENGINE'] = False -# disable elbeem (fluidsim) compilation? -if env['BF_NO_ELBEEM'] == 1: - env['CPPFLAGS'].append('-DDISABLE_ELBEEM') +# build without elbeem (fluidsim)? +if env['WITH_BF_FLUID'] == 1: + env['CPPFLAGS'].append('-DWITH_MOD_FLUID') if btools.ENDIAN == "big": diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index 49efa598ed8..a678bc68f54 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -150,7 +150,9 @@ def validate_arguments(args, bc): 'BF_GHOST_DEBUG', 'WITH_BF_RAYOPTIMIZATION', 'BF_RAYOPTIMIZATION_SSE_FLAGS', - 'BF_NO_ELBEEM', + 'WITH_BF_FLUID', + 'WITH_BF_DECIMATE', + 'WITH_BF_BOOLEAN', 'WITH_BF_CXX_GUARDEDALLOC', 'WITH_BF_JEMALLOC', 'WITH_BF_STATICJEMALLOC', 'BF_JEMALLOC', 'BF_JEMALLOC_INC', 'BF_JEMALLOC_LIBPATH', 'BF_JEMALLOC_LIB', 'BF_JEMALLOC_LIB_STATIC', 'BUILDBOT_BRANCH', 'WITH_BF_3DMOUSE', 'WITH_BF_STATIC3DMOUSE', 'BF_3DMOUSE', 'BF_3DMOUSE_INC', 'BF_3DMOUSE_LIB', 'BF_3DMOUSE_LIBPATH', 'BF_3DMOUSE_LIB_STATIC' @@ -250,7 +252,9 @@ def read_opts(env, cfg, args): (BoolVariable('WITH_OSX_STATICPYTHON', 'Staticly link to python', True)), ('BF_PYTHON_ABI_FLAGS', 'Python ABI flags (suffix in library version: m, mu, etc)', ''), - (BoolVariable('BF_NO_ELBEEM', 'Disable Fluid Sim', False)), + (BoolVariable('WITH_BF_FLUID', 'Build with Fluid simulation (Elbeem)', True)), + (BoolVariable('WITH_BF_DECIMATE', 'Build with decimate modifier', True)), + (BoolVariable('WITH_BF_BOOLEAN', 'Build with boolean modifier', True)), ('BF_PROFILE_FLAGS', 'Profiling compiler flags', ''), (BoolVariable('WITH_BF_OPENAL', 'Use OpenAL if true', False)), ('BF_OPENAL', 'base path for OpenAL', ''), diff --git a/intern/SConscript b/intern/SConscript index 9a78f8ddace..da245c78776 100644 --- a/intern/SConscript +++ b/intern/SConscript @@ -22,7 +22,7 @@ SConscript(['audaspace/SConscript', # perhaps get rid of intern/csg? NEW_CSG='false' -if not env['BF_NO_ELBEEM']: +if env['WITH_BF_FLUID']: SConscript(['elbeem/SConscript']) if NEW_CSG=='false': diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 1930e7223f9..1b98dd914aa 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -323,8 +323,8 @@ if(WITH_OPENMP) add_definitions(-DPARALLEL=1) endif() -if(NOT WITH_MOD_FLUID) - add_definitions(-DDISABLE_ELBEEM) +if(WITH_MOD_FLUID) + add_definitions(-DWITH_MOD_FLUID) endif() if(WITH_MOD_SMOKE) diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 512eec4021f..ebb09352a55 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -79,8 +79,8 @@ if env['OURPLATFORM'] == 'darwin': if env['WITH_BF_OPENMP']: defs.append('PARALLEL=1') -if env['BF_NO_ELBEEM']: - defs.append('DISABLE_ELBEEM') +if env['WITH_BF_FLUID']: + defs.append('WITH_MOD_FLUID') if env['WITH_BF_LZO']: incs += ' #/extern/lzo/minilzo' diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index c4543df0d16..bb14a1ddeaf 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -91,12 +91,12 @@ #include "RE_shader_ext.h" /* fluid sim particle import */ -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID #include "DNA_object_fluidsim.h" #include "LBM_fluidsim.h" #include #include -#endif // DISABLE_ELBEEM +#endif // WITH_MOD_FLUID //XXX #include "BIF_screen.h" diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index f904f246b65..ec058b23050 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -95,13 +95,13 @@ #include "RE_shader_ext.h" /* fluid sim particle import */ -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID #include "DNA_object_fluidsim.h" #include "LBM_fluidsim.h" #include #include -#endif // DISABLE_ELBEEM +#endif // WITH_MOD_FLUID /************************************************/ /* Reacting to system events */ @@ -3916,7 +3916,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) } /* fluid sim particle import handling, actual loading of particles from file */ - #ifndef DISABLE_ELBEEM + #ifdef WITH_MOD_FLUID { FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(sim->ob, eModifierType_Fluidsim); @@ -4009,7 +4009,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) } // fluid sim particles done } - #endif // DISABLE_ELBEEM + #endif // WITH_MOD_FLUID } static int emit_particles(ParticleSimulationData *sim, PTCacheID *pid, float UNUSED(cfra)) diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt index f98122eccbd..382e12cce6c 100644 --- a/source/blender/editors/physics/CMakeLists.txt +++ b/source/blender/editors/physics/CMakeLists.txt @@ -45,8 +45,8 @@ set(SRC physics_intern.h ) -if(NOT WITH_MOD_FLUID) - add_definitions(-DDISABLE_ELBEEM) +if(WITH_MOD_FLUID) + add_definitions(-DWITH_MOD_FLUID) endif() if(WITH_OPENMP) diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index f0c327b9279..6e88d477d9c 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -85,7 +85,7 @@ #include "physics_intern.h" // own include /* enable/disable overall compilation */ -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID #include "WM_api.h" @@ -1111,7 +1111,7 @@ void fluidsimFreeBake(Object *UNUSED(ob)) /* not implemented yet */ } -#else /* DISABLE_ELBEEM */ +#else /* WITH_MOD_FLUID */ /* compile dummy functions for disabled fluid sim */ @@ -1135,7 +1135,7 @@ static int fluidsimBake(bContext *UNUSED(C), ReportList *UNUSED(reports), Object return 0; } -#endif /* DISABLE_ELBEEM */ +#endif /* WITH_MOD_FLUID */ /***************************** Operators ******************************/ diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 59b251317dc..ab69addbbdb 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -195,8 +195,8 @@ if(WITH_CODEC_FFMPEG) add_definitions(-DWITH_FFMPEG) endif() -if(NOT WITH_MOD_FLUID) - add_definitions(-DDISABLE_ELBEEM) +if(WITH_MOD_FLUID) + add_definitions(-DWITH_MOD_FLUID) endif() if(WITH_FFTW3) diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c index d2d24e083b1..a7eedf5f062 100644 --- a/source/blender/makesrna/intern/rna_fluidsim.c +++ b/source/blender/makesrna/intern/rna_fluidsim.c @@ -170,7 +170,7 @@ static void rna_FluidSettings_update_type(Main *bmain, Scene *scene, PointerRNA static void rna_DomainFluidSettings_memory_estimate_get(PointerRNA *ptr, char *value) { -#ifdef DISABLE_ELBEEM +#ifndef WITH_MOD_FLUID (void)ptr; value[0]= '\0'; #else @@ -183,7 +183,7 @@ static void rna_DomainFluidSettings_memory_estimate_get(PointerRNA *ptr, char *v static int rna_DomainFluidSettings_memory_estimate_length(PointerRNA *UNUSED(ptr)) { -#ifdef DISABLE_ELBEEM +#ifndef WITH_MOD_FLUID return 0; #else return 31; diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 7e06ef1d017..805cd913aa0 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -111,8 +111,8 @@ if(WITH_MOD_DECIMATE) ) endif() -if(NOT WITH_MOD_FLUID) - add_definitions(-DDISABLE_ELBEEM) +if(WITH_MOD_FLUID) + add_definitions(-DWITH_MOD_FLUID) endif() if(WITH_GAMEENGINE) diff --git a/source/blender/modifiers/SConscript b/source/blender/modifiers/SConscript index 77a2d577fb5..277ed2c3fb3 100644 --- a/source/blender/modifiers/SConscript +++ b/source/blender/modifiers/SConscript @@ -13,12 +13,14 @@ incs += ' ' + env['BF_ZLIB_INC'] defs = [] -# could be made optional -defs += ['WITH_MOD_BOOLEAN'] -defs += ['WITH_MOD_DECIMATE'] +if env ['WITH_BF_BOOLEAN']: + defs.append('WITH_MOD_BOOLEAN') -if env['BF_NO_ELBEEM']: - defs.append('DISABLE_ELBEEM') +if env ['WITH_BF_DECIMATE']: + defs.append('WITH_MOD_DECIMATE') + +if env['WITH_BF_FLUID']: + defs.append('WITH_MOD_FLUID') if env['WITH_BF_GAMEENGINE']: incs += ' #/extern/recastnavigation' diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index 0e9b71c3e6d..1baa03d2063 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -62,9 +62,10 @@ // headers for fluidsim bobj meshes #include "LBM_fluidsim.h" + void fluidsim_init(FluidsimModifierData *fluidmd) { -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID if(fluidmd) { FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), "fluidsimsettings"); @@ -152,7 +153,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd) void fluidsim_free(FluidsimModifierData *fluidmd) { -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID if(fluidmd) { if(fluidmd->fss->meshVelocities) @@ -169,7 +170,7 @@ void fluidsim_free(FluidsimModifierData *fluidmd) return; } -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID /* read .bobj.gz file into a fluidsimDerivedMesh struct */ static DerivedMesh *fluidsim_read_obj(const char *filename) { @@ -534,14 +535,14 @@ static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData return dm; } -#endif // DISABLE_ELBEEM +#endif // WITH_MOD_FLUID DerivedMesh *fluidsimModifier_do(FluidsimModifierData *fluidmd, Scene *scene, Object *UNUSED(ob), DerivedMesh *dm, int useRenderParams, int UNUSED(isFinalCalc)) { -#ifndef DISABLE_ELBEEM +#ifdef WITH_MOD_FLUID DerivedMesh *result = NULL; int framenr; FluidsimSettings *fss = NULL;