From aeea1d394eef4aa8a41f545932cfae66a0487eba Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 3 Feb 2012 13:08:44 +0000 Subject: [PATCH 01/13] Fix #30028: VSE Paste Strip Crash Crash was caused by invalidation of ID pointers stored in sequencer clipboard when using undo (undo leads to changes in IDs addresses in memory). Restore pointers stored in clipboard in the same way as IDs are restoring for user interface. --- source/blender/blenloader/intern/readfile.c | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 0a92d2ca544..6bd12e8d3f6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5309,6 +5309,30 @@ static void *restore_pointer_by_name(Main *mainp, ID *id, int user) return NULL; } +static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) +{ + Main *newmain = (Main *)arg_pt; + + if(seq->sound) { + seq->sound = restore_pointer_by_name(newmain, (ID *)seq->sound, 0); + seq->sound->id.us++; + } + + if(seq->scene) + seq->scene = restore_pointer_by_name(newmain, (ID *)seq->scene, 1); + + if(seq->scene_camera) + seq->scene_camera = restore_pointer_by_name(newmain, (ID *)seq->scene_camera, 1); + + return 1; +} + +static void lib_link_clipboard_restore(Main *newmain) +{ + /* update IDs stored in sequencer clipboard */ + seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain); +} + /* called from kernel/blender.c */ /* used to link a file (without UI) to the current UI */ /* note that it assumes the old pointers in UI are still valid, so old Main is not freed */ @@ -5516,6 +5540,9 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) sa= sa->next; } } + + /* update IDs stored in all possible clipboards */ + lib_link_clipboard_restore(newmain); } static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) From 1a3da5639e945b115711c244de83a1d11a7b8a21 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 3 Feb 2012 20:12:21 +0000 Subject: [PATCH 02/13] Fix #30064: Image editor: paint on image, rename image, undo -> crash --- source/blender/editors/sculpt_paint/paint_image.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index a5b79d0c974..b8b36954e22 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -474,7 +474,6 @@ static void image_undo_restore(bContext *C, ListBase *lb) } ibuf= BKE_image_get_ibuf(ima, NULL); - use_float = ibuf->rect_float ? 1 : 0; if(ima && ibuf && strcmp(tile->ibufname, ibuf->name)!=0) { /* current ImBuf filename was changed, probably current frame @@ -491,6 +490,8 @@ static void image_undo_restore(bContext *C, ListBase *lb) if (ima->gen_type != tile->gen_type || ima->source != tile->source) continue; + use_float = ibuf->rect_float ? 1 : 0; + if (use_float != tile->use_float) continue; From dc97e07134c48aacf5e3de4436d70e7b71fbecaa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Feb 2012 00:36:55 +0000 Subject: [PATCH 03/13] fix [#30060] self.report printed twice --- .../windowmanager/intern/wm_event_system.c | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 621e5449223..f7da70b6c77 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -457,9 +457,10 @@ void WM_event_print(wmEvent *event) #endif /* NDEBUG */ -static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int popup) +/* (caller_owns_reports == TRUE) when called from python */ +static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int caller_owns_reports) { - if(popup) { + if (caller_owns_reports == FALSE) { /* popup */ if(op->reports->list.first) { /* FIXME, temp setting window, see other call to uiPupMenuReports for why */ wmWindow *win_prev= CTX_wm_window(C); @@ -478,10 +479,15 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int pop } if(retval & OPERATOR_FINISHED) { - if(G.f & G_DEBUG) - wm_operator_print(C, op); /* todo - this print may double up, might want to check more flags then the FINISHED */ - - BKE_reports_print(op->reports, RPT_DEBUG); /* print out reports to console. */ + if(G.f & G_DEBUG) { + /* todo - this print may double up, might want to check more flags then the FINISHED */ + wm_operator_print(C, op); + } + + if (caller_owns_reports == FALSE) { + BKE_reports_print(op->reports, RPT_DEBUG); /* print out reports to console. */ + } + if (op->type->flag & OPTYPE_REGISTER) { if(G.background == 0) { /* ends up printing these in the terminal, gets annoying */ /* Report the python string representation of the operator */ @@ -492,7 +498,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, int pop } } - /* if the caller owns them them handle this */ + /* if the caller owns them, handle this */ if (op->reports->list.first && (op->reports->flag & RPT_OP_HOLD) == 0) { wmWindowManager *wm = CTX_wm_manager(C); @@ -574,7 +580,7 @@ static int wm_operator_exec(bContext *C, wmOperator *op, int repeat) } if (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED) && repeat == 0) - wm_operator_reports(C, op, retval, 0); + wm_operator_reports(C, op, retval, FALSE); if(retval & OPERATOR_FINISHED) wm_operator_finished(C, op, repeat); @@ -817,10 +823,11 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P /* Note, if the report is given as an argument then assume the caller will deal with displaying them * currently python only uses this */ - if (!(retval & OPERATOR_HANDLED) && retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED)) + if (!(retval & OPERATOR_HANDLED) && (retval & (OPERATOR_FINISHED|OPERATOR_CANCELLED))) { /* only show the report if the report list was not given in the function */ - wm_operator_reports(C, op, retval, (reports==NULL)); - + wm_operator_reports(C, op, retval, (reports != NULL)); + } + if(retval & OPERATOR_HANDLED) ; /* do nothing, wm_operator_exec() has been called somewhere */ else if(retval & OPERATOR_FINISHED) { @@ -829,7 +836,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P else if(retval & OPERATOR_RUNNING_MODAL) { /* grab cursor during blocking modal ops (X11) * Also check for macro - * */ + */ if(ot->flag & OPTYPE_BLOCKING || (op->opm && op->opm->type->flag & OPTYPE_BLOCKING)) { int bounds[4] = {-1,-1,-1,-1}; int wrap; @@ -1335,7 +1342,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand } if(retval & (OPERATOR_CANCELLED|OPERATOR_FINISHED)) - wm_operator_reports(C, op, retval, 0); + wm_operator_reports(C, op, retval, FALSE); if(retval & OPERATOR_FINISHED) { wm_operator_finished(C, op, 0); From a05fdb837b89f2fba04587e99d0eecaa9cf174c3 Mon Sep 17 00:00:00 2001 From: Alex Fraser Date: Sat, 4 Feb 2012 01:51:59 +0000 Subject: [PATCH 04/13] Fix for aliased fonts in the game engine. - Mipmaps are generated in BLF when drawing text in-game. In that case, padding around each glyph is increased to prevent bleeding. - Texture filtering is turned on for in-game text. - All glyphs are now "twisted": the leading edge is brought a small distance forward, to prevent z-fighting in overlapping (kerned) glyphs. This happens both in the game engine and the rest of the UI, but should have no effect in the UI due to Z-compression in the clipping matrix. Reviewed and approved by bdiego; see patch [#29882] in the tracker. Tested by dfelinto. --- source/blender/blenfont/BLF_api.h | 1 + source/blender/blenfont/intern/blf_glyph.c | 27 ++++++++++++++++--- .../BlenderRoutines/KX_BlenderGL.cpp | 4 +-- .../GamePlayer/common/GPC_RenderTools.cpp | 4 +-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index a045f47cb40..8752defcc15 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -197,6 +197,7 @@ void BLF_dir_free(char **dirs, int count); #define BLF_KERNING_DEFAULT (1<<3) #define BLF_MATRIX (1<<4) #define BLF_ASPECT (1<<5) +#define BLF_TEXFILTER (1<<6) #define BLF_DRAW_STR_DUMMY_MAX 1024 diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index f0cfcdc97b9..0e7cbb8cf1c 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -54,6 +54,8 @@ #include "blf_internal_types.h" #include "blf_internal.h" +#define _BLF_PADDING 3 +#define _BLF_MIPMAP_LEVELS 3 GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi) { @@ -87,7 +89,11 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) gc->cur_tex= -1; gc->x_offs= 0; gc->y_offs= 0; - gc->pad= 3; + /* Increase padding for each mipmap level: 0->3, 1->4, 2->6, 3->10, ... */ + if (font->flags & BLF_TEXFILTER) + gc->pad= pow(2, _BLF_MIPMAP_LEVELS) + 2; + else + gc->pad= _BLF_PADDING; gc->num_glyphs= font->face->num_glyphs; gc->rem_glyphs= font->face->num_glyphs; @@ -296,13 +302,17 @@ void blf_glyph_free(GlyphBLF *g) static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2) { - + /* When a string is being rendered as individual glyphs (as in the game + * engine), the leading edge needs to be raised a fraction to prevent + * z-fighting for kerned characters. - z0r */ + float twist = (dx1 - dx) * 0.0002; + glBegin(GL_QUADS); glTexCoord2f(uv[0][0], uv[0][1]); - glVertex2f(dx, y1); + glVertex3f(dx, y1, twist); glTexCoord2f(uv[0][0], uv[1][1]); - glVertex2f(dx, y2); + glVertex3f(dx, y2, twist); glTexCoord2f(uv[1][0], uv[1][1]); glVertex2f(dx1, y2); @@ -405,6 +415,15 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) glBindTexture(GL_TEXTURE_2D, g->tex); glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap); + if (font->flags & BLF_TEXFILTER) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, + _BLF_MIPMAP_LEVELS); + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + } glPopClientAttrib(); g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index 7a99a4a1419..78dcfc8edd9 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -136,8 +136,8 @@ void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* /* the actual drawing */ glColor4fv(color); + BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER); /* multiply the text matrix by the object matrix */ - BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ @@ -149,7 +149,7 @@ void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, (char *)text, 65535); - BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); + BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER); } void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height) diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index ffa2cb38b87..b06a9783b50 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -294,8 +294,8 @@ void GPC_RenderTools::RenderText3D( int fontid, /* the actual drawing */ glColor3fv(color); + BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER); /* multiply the text matrix by the object matrix */ - BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ @@ -307,7 +307,7 @@ void GPC_RenderTools::RenderText3D( int fontid, BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, text, 65535); - BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); + BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT|BLF_TEXFILTER); glEnable(GL_DEPTH_TEST); } From deec4ce0bc77519f68392bc5b29ef211a31f1588 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Feb 2012 06:55:29 +0000 Subject: [PATCH 05/13] Code Cleanup: avoid double promotion. --- source/blender/blenfont/intern/blf_glyph.c | 2 +- source/blender/blenkernel/intern/cloth.c | 2 +- source/blender/blenkernel/intern/constraint.c | 4 ++-- source/blender/blenkernel/intern/fcurve.c | 2 +- source/blender/blenkernel/intern/seqeffects.c | 6 +++--- source/blender/blenlib/intern/math_color.c | 2 +- source/blender/editors/interface/interface_draw.c | 4 ++-- source/blender/editors/physics/physics_fluid.c | 2 +- source/blender/editors/sculpt_paint/sculpt.c | 2 +- source/blender/editors/space_clip/clip_graph_ops.c | 2 +- source/blender/editors/space_sequencer/sequencer_scopes.c | 2 +- source/blender/editors/transform/transform.c | 4 ++-- source/blender/modifiers/intern/MOD_meshdeform.c | 2 +- source/blender/render/intern/source/occlusion.c | 2 +- source/blender/render/intern/source/zbuf.c | 2 +- 15 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 0e7cbb8cf1c..ab7ef8072a9 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -305,7 +305,7 @@ static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, floa /* When a string is being rendered as individual glyphs (as in the game * engine), the leading edge needs to be raised a fraction to prevent * z-fighting for kerned characters. - z0r */ - float twist = (dx1 - dx) * 0.0002; + const float twist = (dx1 - dx) * 0.0002f; glBegin(GL_QUADS); glTexCoord2f(uv[0][0], uv[0][1]); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index d86fc5c9aef..1beaa59baad 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -1151,7 +1151,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->kl = MAX2(mface[i].v4, mface[i].v2); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); spring->type = CLOTH_SPRING_TYPE_SHEAR; - spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0; + spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f; BLI_linklist_append ( &edgelist[spring->ij], spring ); BLI_linklist_append ( &edgelist[spring->kl], spring ); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 33b17f27ac8..ad89a9c959f 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -492,7 +492,7 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat copy_v3_v3(plane, tmat[1]); cross_v3_v3v3(mat[0], normal, plane); - if(len_v3(mat[0]) < 1e-3) { + if(len_v3(mat[0]) < 1e-3f) { copy_v3_v3(plane, tmat[0]); cross_v3_v3v3(mat[0], normal, plane); } @@ -1263,7 +1263,7 @@ static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr /* If the curve is cyclic, enable looping around if the time is * outside the bounds 0..1 */ if ((curvetime < 0.0f) || (curvetime > 1.0f)) { - curvetime -= floor(curvetime); + curvetime -= floorf(curvetime); } } else { diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 318165af804..5feeb4c300d 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1987,7 +1987,7 @@ static float fcurve_eval_keyframes (FCurve *fcu, BezTriple *bezts, float evaltim for (a=0; prevbezt && bezt && (a < fcu->totvert-1); a++, prevbezt=bezt, bezt++) { /* use if the key is directly on the frame, rare cases this is needed else we get 0.0 instead. */ - if(fabs(bezt->vec[1][0] - evaltime) < SMALL_NUMBER) { + if(fabsf(bezt->vec[1][0] - evaltime) < SMALL_NUMBER) { cvalue= bezt->vec[1][1]; } /* evaltime occurs within the interval defined by these two keyframes */ diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index a8f89b0a1eb..9edcc7a73e8 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -1583,7 +1583,7 @@ typedef struct WipeZone { static void precalc_wipe_zone(WipeZone *wipezone, WipeVars *wipe, int xo, int yo) { wipezone->flip = (wipe->angle < 0); - wipezone->angle = tan(DEG2RAD(fabsf(wipe->angle))); + wipezone->angle = tanf(DEG2RADF(fabsf(wipe->angle))); wipezone->xo = xo; wipezone->yo = yo; wipezone->width = (int)(wipe->edgeWidth*((xo+yo)/2.0f)); @@ -1602,9 +1602,9 @@ static float in_band(float width,float dist,int side,int dir) return (float)side; if(side == 1) - alpha = (dist+0.5*width) / (width); + alpha = (dist+0.5f*width) / (width); else - alpha = (0.5*width-dist) / (width); + alpha = (0.5f*width-dist) / (width); if(dir == 0) alpha = 1-alpha; diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index ca2aeca8f36..b9772b1f3b4 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -561,7 +561,7 @@ void BLI_init_srgb_conversion(void) for (i = 0; i < 0x10000; i++) { float f = linearrgb_to_srgb(index_to_float(i))*255.0f; if (f <= 0) BLI_color_to_srgb_table[i] = 0; - else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short)(f*0x100+.5); + else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short)(f*0x100+0.5f); else BLI_color_to_srgb_table[i] = 0xff00; } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 9b7c49023c5..93cb0f8ae97 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1533,8 +1533,8 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc zoomx= (float)width / (scopes->track_preview->x-2*margin); zoomy= (float)height / (scopes->track_preview->y-2*margin); - off_x= ((int)track_pos[0]-track_pos[0]+0.5)*zoomx; - off_y= ((int)track_pos[1]-track_pos[1]+0.5)*zoomy; + off_x= ((int)track_pos[0]-track_pos[0]+0.5f)*zoomx; + off_y= ((int)track_pos[1]-track_pos[1]+0.5f)*zoomy; drawibuf= scale_trackpreview_ibuf(scopes->track_preview, track_pos, width, height, margin); diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index dbc153de108..c528d8cd078 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -109,7 +109,7 @@ static float get_fluid_viscosity(FluidsimSettings *settings) return 2.0e-3; case 1: /* manual */ default: - return (1.0/pow(10.0, settings->viscosityExponent)) * settings->viscosityValue; + return (1.0f/powf(10.0f, settings->viscosityExponent)) * settings->viscosityValue; } } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index ce84e43955b..d05582512ae 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3153,7 +3153,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, dx = cache->mouse[0] - cache->initial_mouse[0]; dy = cache->mouse[1] - cache->initial_mouse[1]; - cache->vertex_rotation = -atan2(dx, dy) * cache->bstrength; + cache->vertex_rotation = -atan2f(dx, dy) * cache->bstrength; sd->draw_anchored = 1; copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse); diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index 6a56de26689..f902422ab43 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -450,7 +450,7 @@ void CLIP_OT_graph_view_all(wmOperatorType *ot) void ED_clip_graph_center_current_frame(Scene *scene, ARegion *ar) { View2D *v2d = &ar->v2d; - float extra = (v2d->cur.xmax - v2d->cur.xmin) / 2.0; + float extra = (v2d->cur.xmax - v2d->cur.xmin) / 2.0f; /* set extents of view to start/end frames */ v2d->cur.xmin = (float)CFRA - extra; diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index 2bb40ce51f4..c13a5202c19 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -170,7 +170,7 @@ static struct ImBuf *make_waveform_view_from_ibuf_byte(struct ImBuf * ibuf) for (x = 0; x < ibuf->x; x++) { unsigned char * rgb = src + 4 * (ibuf->x * y + x); - float v = (float)rgb_to_luma_byte(rgb) / 255.0; + float v = (float)rgb_to_luma_byte(rgb) / 255.0f; unsigned char * p = tgt; p += 4 * (w * ((int) (v * (h - 3)) + 1) + x + 1); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 41e7356ad10..9d368476f03 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -5566,9 +5566,9 @@ static void headerTimeTranslate(TransInfo *t, char *str) /* apply snapping + frame->seconds conversions */ if (autosnap == SACTSNAP_STEP) { if (doTime) - val= floor((double)val/secf + 0.5f); + val= floorf((double)val/secf + 0.5f); else - val= floor(val + 0.5f); + val= floorf(val + 0.5f); } else { if (doTime) diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index e6e2c0fd621..d80c6715f9d 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -298,7 +298,7 @@ static void meshdeformModifier_do( fac= 1.0f - fac; } - if (fac <= 0.0) { + if (fac <= 0.0f) { continue; } } diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c index 782e0b59388..669355c9977 100644 --- a/source/blender/render/intern/source/occlusion.c +++ b/source/blender/render/intern/source/occlusion.c @@ -1408,7 +1408,7 @@ static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude, f occlusion= (1.0f-correction)*(1.0f-occ); CLAMP(occlusion, 0.0f, 1.0f); if(correction != 0.0f) - occlusion += correction*exp(-occ); + occlusion += correction*expf(-occ); if(env) { /* sky shading using bent normal */ diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 0d5aed7dadb..807a3d7d0eb 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -245,7 +245,7 @@ int testclip(const float v[4]) /* if we set clip flags, the clipping should be at least larger than epsilon. prevents issues with vertices lying exact on borders */ - abs4= fabs(v[3]) + FLT_EPSILON; + abs4= fabsf(v[3]) + FLT_EPSILON; if( v[0] < -abs4) c+=1; else if( v[0] > abs4) c+=2; From d84573386e5ee0c63d8f4bebb3984fc6385bcb90 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Sat, 4 Feb 2012 10:02:59 +0000 Subject: [PATCH 06/13] Fix MinGW compilation due to recent font rendering changes. GLEW_STATIC needs to be defined for static linking of GLEW or the dynamic entry points are looked up during linking --- source/blender/blenfont/CMakeLists.txt | 2 ++ source/blender/blenfont/SConscript | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/source/blender/blenfont/CMakeLists.txt b/source/blender/blenfont/CMakeLists.txt index d9282978562..ebf9ff4db39 100644 --- a/source/blender/blenfont/CMakeLists.txt +++ b/source/blender/blenfont/CMakeLists.txt @@ -57,5 +57,7 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +add_definitions(-DGLEW_STATIC) + blender_add_lib(bf_blenfont "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/blenfont/SConscript b/source/blender/blenfont/SConscript index 1a86d0ad671..c46960d2311 100644 --- a/source/blender/blenfont/SConscript +++ b/source/blender/blenfont/SConscript @@ -9,7 +9,7 @@ incs += ' #/extern/glew/include' incs += ' ' + env['BF_FREETYPE_INC'] incs += ' ' + env['BF_GETTEXT_INC'] -defs = [] +defs = ['GLEW_STATIC'] if sys.platform == 'win32' or env['OURPLATFORM'] == 'linuxcross': defs.append('_WIN32') From 637bc0ddea8b7badf7231075e34b0a8ef5aa7c36 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Feb 2012 11:10:41 +0000 Subject: [PATCH 07/13] Code Cleanup: pep8 edits --- build_files/cmake/cmake_static_check_cppcheck.py | 2 +- intern/cycles/blender/addon/ui.py | 2 +- release/scripts/startup/bl_operators/object.py | 3 ++- .../startup/bl_ui/properties_data_modifier.py | 4 ++-- .../startup/bl_ui/properties_object_constraint.py | 10 +++++----- release/scripts/startup/bl_ui/space_clip.py | 12 ++++++++---- release/scripts/startup/bl_ui/space_image.py | 5 +++-- release/scripts/startup/bl_ui/space_node.py | 2 +- source/tests/bl_run_operators.py | 2 +- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/build_files/cmake/cmake_static_check_cppcheck.py b/build_files/cmake/cmake_static_check_cppcheck.py index 6c13f3a079a..436470a7020 100644 --- a/build_files/cmake/cmake_static_check_cppcheck.py +++ b/build_files/cmake/cmake_static_check_cppcheck.py @@ -37,7 +37,7 @@ CHECKER_BIN = "cppcheck" CHECKER_ARGS = [ # not sure why this is needed, but it is. "-I" + os.path.join(project_source_info.SOURCE_DIR, "extern", "glew", "include"), - "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR, + "--suppress=*:%s/extern/glew/include/GL/glew.h:241" % project_source_info.SOURCE_DIR, # "--max-configs=1", # speeds up execution # "--check-config", # when includes are missing # "--enable=all", # if you want sixty hundred pedantic suggestions diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index c82ab9ce624..c966792ed29 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -370,7 +370,7 @@ class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel): visibility = ob.cycles_visibility flow = layout.column_flow() - + flow.prop(visibility, "camera") flow.prop(visibility, "diffuse") flow.prop(visibility, "glossy") diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py index 923a259c69c..b7c6b858913 100644 --- a/release/scripts/startup/bl_operators/object.py +++ b/release/scripts/startup/bl_operators/object.py @@ -493,7 +493,8 @@ class ShapeTransfer(Operator): def execute(self, context): ob_act = context.active_object - objects = [ob for ob in context.selected_editable_objects if ob != ob_act] + objects = [ob for ob in context.selected_editable_objects + if ob != ob_act] if 1: # swap from/to, means we cant copy to many at once. if len(objects) != 1: diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 766daba58b8..354b70c19c2 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -814,12 +814,12 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): def REMESH(self, layout, ob, md): layout.prop(md, "mode") - + row = layout.row() row.prop(md, "octree_depth") row.prop(md, "scale") - if md.mode == "SHARP": + if md.mode == 'SHARP': layout.prop(md, "sharpness") layout.prop(md, "remove_disconnected_pieces") diff --git a/release/scripts/startup/bl_ui/properties_object_constraint.py b/release/scripts/startup/bl_ui/properties_object_constraint.py index dff23e6238f..68c00691122 100644 --- a/release/scripts/startup/bl_ui/properties_object_constraint.py +++ b/release/scripts/startup/bl_ui/properties_object_constraint.py @@ -435,23 +435,23 @@ class ConstraintButtonsPanel(): self.target_template(layout, con) split = layout.split() - + col = split.column() col.label(text="From Target:") col.prop(con, "transform_channel", text="") col.prop(con, "target_space", text="") - + col = split.column() col.label(text="To Action:") col.prop(con, "action", text="") - + split = layout.split() - + col = split.column(align=True) col.label(text="Target Range:") col.prop(con, "min", text="Min") col.prop(con, "max", text="Max") - + col = split.column(align=True) col.label(text="Action Range:") col.prop(con, "frame_start", text="Start") diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index c879609de95..8ebc1c450b4 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -128,9 +128,12 @@ class CLIP_PT_tools_marker(Panel): col.separator() row = col.row(align=True) - row.prop(settings, "use_default_red_channel", text="R", toggle=True) - row.prop(settings, "use_default_green_channel", text="G", toggle=True) - row.prop(settings, "use_default_blue_channel", text="B", toggle=True) + row.prop(settings, "use_default_red_channel", + text="R", toggle=True) + row.prop(settings, "use_default_green_channel", + text="G", toggle=True) + row.prop(settings, "use_default_blue_channel", + text="B", toggle=True) col.separator() @@ -155,7 +158,8 @@ class CLIP_PT_tools_marker(Panel): col.prop(settings, "default_pattern_match", text="") col.separator() - col.operator('clip.track_settings_as_default', text="Copy From Active Track") + col.operator('clip.track_settings_as_default', + text="Copy From Active Track") class CLIP_PT_tools_tracking(Panel): diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index a41ae92b4b6..c0cc692f2f1 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -21,6 +21,7 @@ import bpy from bpy.types import Header, Menu, Panel from .properties_paint_common import UnifiedPaintPanel + class ImagePaintPanel(UnifiedPaintPanel): bl_space_type = 'IMAGE_EDITOR' bl_region_type = 'UI' @@ -677,7 +678,7 @@ class IMAGE_PT_paint(Panel, ImagePaintPanel): row = col.row(align=True) self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength") self.prop_unified_strength(row, context, brush, "use_pressure_strength") - + row = col.row(align=True) row.prop(brush, "jitter", slider=True) row.prop(brush, "use_pressure_jitter", toggle=True, text="") @@ -826,7 +827,7 @@ class IMAGE_UV_sculpt(Panel, ImagePaintPanel): row = col.row(align=True) self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength") self.prop_unified_strength(row, context, brush, "use_pressure_strength") - + split = layout.split() col = split.column() diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py index d29dff49132..0114f33928a 100644 --- a/release/scripts/startup/bl_ui/space_node.py +++ b/release/scripts/startup/bl_ui/space_node.py @@ -58,7 +58,7 @@ class NODE_HT_header(Header): # Don't show "Use Nodes" Button when Engine is BI for Lamps if snode_id and not (scene.render.use_shading_nodes == 0 and ob.type == 'LAMP'): layout.prop(snode_id, "use_nodes") - + if snode.shader_type == 'WORLD': layout.template_ID(scene, "world", new="world.new") if snode_id: diff --git a/source/tests/bl_run_operators.py b/source/tests/bl_run_operators.py index b3781e94696..08e9d5d59e4 100644 --- a/source/tests/bl_run_operators.py +++ b/source/tests/bl_run_operators.py @@ -142,7 +142,7 @@ def bpy_check_type_duplicates(): # non essential sanity check bl_types = dir(bpy.types) bl_types_unique = set(bl_types) - + if len(bl_types) != len(bl_types_unique): print("Error, found duplicates in 'bpy.types'") for t in sorted(bl_types_unique): From 6927dcbf6f8999c89386fe56695aea7c8544d50e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Feb 2012 11:12:18 +0000 Subject: [PATCH 08/13] fix [#30068] Link Empty to Track python error incorrect attribute used (likely code added since last release). --- release/scripts/startup/bl_operators/clip.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py index 77c28b1bc11..aa4f3a35e6d 100644 --- a/release/scripts/startup/bl_operators/clip.py +++ b/release/scripts/startup/bl_operators/clip.py @@ -69,7 +69,7 @@ def CLIP_camera_for_clip(context, clip): if ob.type == 'CAMERA': for con in ob.constraints: if con.type == 'CAMERA_SOLVER': - cur_clip = scene.clip if con.use_active_clip else con.clip + cur_clip = scene.active_clip if con.use_active_clip else con.clip if cur_clip == clip: return ob @@ -834,6 +834,7 @@ class CLIP_OT_setup_tracking_scene(Operator): return {'FINISHED'} + class CLIP_OT_track_settings_as_default(Operator): """Copy tracking settings from active track to default settings""" From fc0ce537bab8731cc60fda282a6c97d4816011e5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Feb 2012 11:59:09 +0000 Subject: [PATCH 09/13] fix [#29947] Blender crashes when duplicate bones missing NULL check. --- source/blender/editors/animation/anim_deps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index fdccf5d4baa..3f851938a83 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -148,7 +148,7 @@ static void animchan_sync_group (bAnimContext *UNUSED(ac), bAnimListElem *ale) /* if one matches, sync the selection status */ if (pchan) { - if (pchan->bone->flag & BONE_SELECTED) + if (pchan->bone && pchan->bone->flag & BONE_SELECTED) agrp->flag |= AGRP_SELECTED; else agrp->flag &= ~AGRP_SELECTED; From 4c7e769aa1e617b1748500d73904921e7a66791d Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 4 Feb 2012 17:20:38 +0000 Subject: [PATCH 10/13] BGE bug #29133: Render to Texture not working. Fixed by using same viewport to render and capture. --- source/gameengine/VideoTexture/ImageViewport.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/gameengine/VideoTexture/ImageViewport.cpp b/source/gameengine/VideoTexture/ImageViewport.cpp index 036dd893dcb..a9354564d0e 100644 --- a/source/gameengine/VideoTexture/ImageViewport.cpp +++ b/source/gameengine/VideoTexture/ImageViewport.cpp @@ -31,6 +31,7 @@ http://www.gnu.org/copyleft/lesser.txt. #include "GL/glew.h" +#include "KX_PythonInit.h" #include "Texture.h" #include "ImageBase.h" #include "FilterSource.h" @@ -41,7 +42,13 @@ http://www.gnu.org/copyleft/lesser.txt. ImageViewport::ImageViewport (void) : m_alpha(false), m_texInit(false) { // get viewport rectangle - glGetIntegerv(GL_VIEWPORT, m_viewport); + RAS_Rect rect = KX_GetActiveEngine()->GetCanvas()->GetWindowArea(); + m_viewport[0] = rect.GetLeft(); + m_viewport[1] = rect.GetBottom(); + m_viewport[2] = rect.GetWidth(); + m_viewport[3] = rect.GetHeight(); + + //glGetIntegerv(GL_VIEWPORT, m_viewport); // create buffer for viewport image m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]]; // set attributes From 04266c22254bb02cc030be04f1bd58cb3cf450fe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 4 Feb 2012 19:57:09 +0000 Subject: [PATCH 11/13] Fix: non-power-of-two-textures were always disabled on ATI/Apple due to poor support in some older cards, now it does a more precise check for problematic cards so that it can be enabled on new cards that do support it properly. --- source/blender/gpu/intern/gpu_extensions.c | 37 +++++++++------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index cc486b75245..a6672130dc3 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -126,12 +126,6 @@ void GPU_extensions_init(void) if(strstr(vendor, "ATI")) { GG.device = GPU_DEVICE_ATI; GG.driver = GPU_DRIVER_OFFICIAL; - - /* ATI X1xxx cards (R500 chipset) lack full support for npot textures - * although they report the GLEW_ARB_texture_non_power_of_two extension. - */ - if(strstr(renderer, "X1")) - GG.npotdisabled = 1; } else if(strstr(vendor, "NVIDIA")) { GG.device = GPU_DEVICE_NVIDIA; @@ -147,17 +141,6 @@ void GPU_extensions_init(void) else if(strstr(renderer, "Mesa DRI R") || (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI "))) { GG.device = GPU_DEVICE_ATI; GG.driver = GPU_DRIVER_OPENSOURCE; - /* ATI 9500 to X2300 cards support NPoT textures poorly - * Incomplete list http://dri.freedesktop.org/wiki/ATIRadeon - * New IDs from MESA's src/gallium/drivers/r300/r300_screen.c - */ - if(strstr(renderer, "R3") || strstr(renderer, "RV3") || - strstr(renderer, "R4") || strstr(renderer, "RV4") || - strstr(renderer, "RS4") || strstr(renderer, "RC4") || - strstr(renderer, "R5") || strstr(renderer, "RV5") || - strstr(renderer, "RS600") || strstr(renderer, "RS690") || - strstr(renderer, "RS740")) - GG.npotdisabled = 1; } else if(strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) { GG.device = GPU_DEVICE_NVIDIA; @@ -180,6 +163,21 @@ void GPU_extensions_init(void) GG.driver = GPU_DRIVER_ANY; } + if(GG.device == GPU_DEVICE_ATI) { + /* ATI 9500 to X2300 cards support NPoT textures poorly + * Incomplete list http://dri.freedesktop.org/wiki/ATIRadeon + * New IDs from MESA's src/gallium/drivers/r300/r300_screen.c + */ + if(strstr(renderer, "R3") || strstr(renderer, "RV3") || + strstr(renderer, "R4") || strstr(renderer, "RV4") || + strstr(renderer, "RS4") || strstr(renderer, "RC4") || + strstr(renderer, "R5") || strstr(renderer, "RV5") || + strstr(renderer, "RS600") || strstr(renderer, "RS690") || + strstr(renderer, "RS740") || strstr(renderer, "X1") || + strstr(renderer, "X2")) + GG.npotdisabled = 1; + } + GG.os = GPU_OS_UNIX; #ifdef _WIN32 GG.os = GPU_OS_WIN; @@ -202,11 +200,6 @@ int GPU_glsl_support(void) int GPU_non_power_of_two_support(void) { - /* Exception for buggy ATI/Apple driver in Mac OS X 10.5/10.6, - * they claim to support this but can cause system freeze */ - if(GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_MAC, GPU_DRIVER_OFFICIAL)) - return 0; - if(GG.npotdisabled) return 0; From 5c395b69f55560e20c4c1f3e972b8e0759c647c2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 4 Feb 2012 19:58:09 +0000 Subject: [PATCH 12/13] Fix for Luxrender boost::thread conflict, workaround now is to just not use it in cycles and use pthreads instead. --- intern/cycles/SConscript | 3 ++ intern/cycles/util/util_thread.h | 53 +++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/intern/cycles/SConscript b/intern/cycles/SConscript index bc9eb563e50..2ea224f052d 100644 --- a/intern/cycles/SConscript +++ b/intern/cycles/SConscript @@ -39,6 +39,9 @@ if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'): else: cxxflags.append('-ffast-math'.split()) +if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): + incs.append(env['BF_PTHREADS_INC']) + # optimized kernel if env['WITH_BF_RAYOPTIMIZATION']: optim_cxxflags = [] diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h index ad95f04b4f9..6836be203f5 100644 --- a/intern/cycles/util/util_thread.h +++ b/intern/cycles/util/util_thread.h @@ -20,29 +20,54 @@ #define __UTIL_THREAD_H__ #include +#include #include +#include "util_function.h" + CCL_NAMESPACE_BEGIN -#if 0 +/* use boost for mutexes */ -/* Use STL for threading */ - -using std::thread; -using std::thread_mutex; -typedef std::lock_guard thread_scoped_lock; -using std::condition_variable; - -#else - -/* Use boost for threading */ - -using boost::thread; typedef boost::mutex thread_mutex; typedef boost::mutex::scoped_lock thread_scoped_lock; typedef boost::condition_variable thread_condition_variable; -#endif +/* own pthread based implementation, to avoid boost version conflicts with + dynamically loaded blender plugins */ + +class thread { +public: + thread(boost::function run_cb_) + { + joined = false; + run_cb = run_cb_; + + pthread_create(&pthread_id, NULL, run, (void*)this); + } + + ~thread() + { + if(!joined) + join(); + } + + static void *run(void *arg) + { + ((thread*)arg)->run_cb();; + return NULL; + } + + bool join() + { + return pthread_join(pthread_id, NULL) == 0; + } + +protected: + boost::function run_cb; + pthread_t pthread_id; + bool joined; +}; /* Thread Safe Queue to pass tasks from one thread to another. Tasks should be * pushed into the queue, while the worker thread waits to pop the next task From 4acab3eb33db20eef89d0159199429c690b0f2df Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Feb 2012 02:04:26 +0000 Subject: [PATCH 13/13] Code Cleanup: line length and use Py_ssize_t for PyC_AsArray utility function. --- source/blender/python/generic/py_capi_utils.c | 16 +++++++----- source/blender/python/generic/py_capi_utils.h | 3 ++- .../blender/python/intern/bpy_operator_wrap.c | 8 ++++-- source/blender/python/intern/bpy_rna.c | 26 ++++++++++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 43b8dc21300..ebc9a61f604 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -35,18 +35,20 @@ #include "py_capi_utils.h" -#include "BLI_string_utf8.h" /* only for BLI_strncpy_wchar_from_utf8, should replace with py funcs but too late in release now */ +/* only for BLI_strncpy_wchar_from_utf8, should replace with py funcs but too late in release now */ +#include "BLI_string_utf8.h" #ifdef _WIN32 /* BLI_setenv */ #include "BLI_path_util.h" #endif /* array utility function */ -int PyC_AsArray(void *array, PyObject *value, const int length, const PyTypeObject *type, const short is_double, const char *error_prefix) +int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length, + const PyTypeObject *type, const short is_double, const char *error_prefix) { PyObject *value_fast; - int value_len; - int i; + Py_ssize_t value_len; + Py_ssize_t i; if (!(value_fast=PySequence_Fast(value, error_prefix))) { return -1; @@ -463,7 +465,8 @@ void PyC_SetHomePath(const char *py_path_bundle) if (py_path_bundle==NULL) { /* Common enough to have bundled *nix python but complain on OSX/Win */ #if defined(__APPLE__) || defined(_WIN32) - fprintf(stderr, "Warning! bundled python not found and is expected on this platform. (if you built with CMake: 'install' target may have not been built)\n"); + fprintf(stderr, "Warning! bundled python not found and is expected on this platform. " + "(if you built with CMake: 'install' target may have not been built)\n"); #endif return; } @@ -492,7 +495,8 @@ void PyC_SetHomePath(const char *py_path_bundle) /* cant use this, on linux gives bug: #23018, TODO: try LANG="en_US.UTF-8" /usr/bin/blender, suggested 22008 */ /* mbstowcs(py_path_bundle_wchar, py_path_bundle, FILE_MAXDIR); */ - BLI_strncpy_wchar_from_utf8(py_path_bundle_wchar, py_path_bundle, sizeof(py_path_bundle_wchar) / sizeof(wchar_t)); + BLI_strncpy_wchar_from_utf8(py_path_bundle_wchar, py_path_bundle, + sizeof(py_path_bundle_wchar) / sizeof(wchar_t)); Py_SetPythonHome(py_path_bundle_wchar); // printf("found python (wchar_t) '%ls'\n", py_path_bundle_wchar); diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 17d83ca6567..2cab464a9d7 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -35,7 +35,8 @@ PyObject * PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...); PyObject * PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...); void PyC_FileAndNum(const char **filename, int *lineno); void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */ -int PyC_AsArray(void *array, PyObject *value, const int length, const PyTypeObject *type, const short is_double, const char *error_prefix); +int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length, + const PyTypeObject *type, const short is_double, const char *error_prefix); /* follow http://www.python.org/dev/peps/pep-0383/ */ PyObject * PyC_UnicodeFromByte(const char *str); diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 7860762059c..39780e7e257 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -112,7 +112,9 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args) return NULL; if (WM_operatortype_find(opname, TRUE) == NULL) { - PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid operator id", opname); + PyErr_Format(PyExc_ValueError, + "Macro Define: '%s' is not a valid operator id", + opname); return NULL; } @@ -123,7 +125,9 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args) ot = WM_operatortype_find(macroname, TRUE); if (!ot) { - PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname); + PyErr_Format(PyExc_ValueError, + "Macro Define: '%s' is not a valid macro or hasn't been registered yet", + macroname); return NULL; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 11e79fdee2a..fa2a20a10e6 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2571,7 +2571,8 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject return NULL; } else if (key_slice->start == Py_None && key_slice->stop == Py_None) { - /* note, no significant advantage with optimizing [:] slice as with collections but include here for consistency with collection slice func */ + /* note, no significant advantage with optimizing [:] slice as with collections + * but include here for consistency with collection slice func */ Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self); return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); } @@ -2834,7 +2835,8 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) const char *keyname = _PyUnicode_AsString(key); if (keyname == NULL) { - PyErr_SetString(PyExc_TypeError, "bpy_prop_collection.__contains__: expected a string or a typle of strings"); + PyErr_SetString(PyExc_TypeError, + "bpy_prop_collection.__contains__: expected a string or a typle of strings"); return -1; } @@ -5102,7 +5104,14 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject #ifdef DEBUG_STRING_FREE - // if (PyList_GET_SIZE(string_free_ls)) printf("%.200s.%.200s(): has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_GET_SIZE(string_free_ls)); + /* + if (PyList_GET_SIZE(string_free_ls)) { + printf("%.200s.%.200s(): has %d strings\n", + RNA_struct_identifier(self_ptr->type), + RNA_function_identifier(self_func), + (int)PyList_GET_SIZE(string_free_ls)); + } + */ Py_DECREF(string_free_ls); #undef DEBUG_STRING_FREE #endif @@ -5126,7 +5135,10 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject PyTypeObject pyrna_struct_meta_idprop_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_struct_meta_idprop", /* tp_name */ - sizeof(PyHeapTypeObject), /* tp_basicsize */ // XXX, would be PyTypeObject, but subtypes of Type must be PyHeapTypeObject's + + /* NOTE! would be PyTypeObject, but subtypes of Type must be PyHeapTypeObject's */ + sizeof(PyHeapTypeObject), /* tp_basicsize */ + 0, /* tp_itemsize */ /* methods */ NULL, /* tp_dealloc */ @@ -5380,16 +5392,16 @@ PyTypeObject pyrna_prop_Type = { PyTypeObject pyrna_prop_array_Type = { PyVarObject_HEAD_INIT(NULL, 0) - "bpy_prop_array", /* tp_name */ + "bpy_prop_array", /* tp_name */ sizeof(BPy_PropertyArrayRNA), /* tp_basicsize */ - 0, /* tp_itemsize */ + 0, /* tp_itemsize */ /* methods */ (destructor)pyrna_prop_array_dealloc, /* tp_dealloc */ NULL, /* printfunc tp_print; */ NULL, /* getattrfunc tp_getattr; */ NULL, /* setattrfunc tp_setattr; */ NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */ - NULL,/* subclassed */ /* tp_repr */ + NULL,/* subclassed */ /* tp_repr */ /* Method suites for standard classes */