[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29874] branches/soc-2010-jwilkins: == Brush Preview Icon Fixed ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Jul 2 19:37:56 CEST 2010


Revision: 29874
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29874
Author:   jwilkins
Date:     2010-07-02 19:37:55 +0200 (Fri, 02 Jul 2010)

Log Message:
-----------
== Brush Preview Icon Fixed ==
Fixed crash with brush preview icons, problem was that an address translation for the image icon was needed when loading the brush into memory.  This explains why the pointer causing the crash was not a null pointer.  Instead it was an old pointer from the previous session.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c
    branches/soc-2010-jwilkins/source/blender/blenkernel/intern/icons.c
    branches/soc-2010-jwilkins/source/blender/blenkernel/intern/image.c
    branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c
    branches/soc-2010-jwilkins/source/blender/blenloader/intern/writefile.c
    branches/soc-2010-jwilkins/source/blender/editors/interface/interface_icons.c
    branches/soc-2010-jwilkins/source/blender/editors/render/render_preview.c
    branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-07-02 17:37:55 UTC (rev 29874)
@@ -1018,9 +1018,9 @@
             sub = col.column()
             sub.prop(brush, "add_col", text="Color")
 
-        #col.separator()
-        #col.label(text="Icon:")
-        #col.template_ID_preview(brush, "image_icon", open="image.open", rows=3, cols=4)
+        col.separator()
+        col.label(text="Icon:")
+        col.template_ID_preview(brush, "image_icon", open="image.open", rows=3, cols=4)
 
         col.separator()
         split = self.layout.split()

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -124,8 +124,7 @@
 	brush->id.flag |= LIB_FAKEUSER;
 	brush_toggled_fake_user(brush);
 	
-	//brush->preview = NULL;
-	//brush->image_icon = NULL;
+	brush->image_icon = NULL;
 
 	return brush;
 }
@@ -154,8 +153,6 @@
 {
 	if(brush->mtex.tex) brush->mtex.tex->id.us--;
 
-	// BKE_previewimg_free(&brush->preview);  // XXX:image_icon
-
 	curvemapping_free(brush->curve);
 }
 

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/icons.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/icons.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/icons.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -177,16 +177,7 @@
 	} else if (GS(id->name) == ID_IM) {
 		Image *img  = (Image*)id;
 		BKE_previewimg_free(&img->preview);
-	} /* else if (GS(id->name) == ID_BR) {
-		Brush *br = (Brush*)id;
-		if (br->image_icon) {
-			BKE_previewimg_free(&br->preview);
-		}
-		else {
-			if (br->mtex.tex)
-				BKE_previewimg_free(&br->mtex.tex->preview);
-		}
-	} */  // XXX:image_icon
+	}
 }
 
 PreviewImage* BKE_previewimg_get(ID *id) 
@@ -213,22 +204,8 @@
 		Image *img  = (Image*)id;
 		if (!img->preview) img->preview = BKE_previewimg_create();
 		prv_img = img->preview;
-	} /* else if (GS(id->name) == ID_BR) {
-		Brush *br = (Brush*)id;
-		if (br->image_icon) {
-			if (!br->preview)
-				br->preview = BKE_previewimg_create();
+	}
 
-			prv_img = br->preview;
-		}
-		else {
-			if (br->mtex.tex && !br->mtex.tex->preview)
-				br->mtex.tex->preview = BKE_previewimg_create();
-
-			prv_img = br->mtex.tex ? br->mtex.tex->preview : NULL;
-		}
-	} */  // XXX:image_icon
-
 	return prv_img;
 }
 

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/image.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/image.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -200,9 +200,9 @@
 	}
 	BKE_icon_delete(&ima->id);
 	ima->id.icon_id = 0;
-	if (ima->preview) {
-		BKE_previewimg_free(&ima->preview);
-	}
+
+	BKE_previewimg_free(&ima->preview);
+
 	for(a=0; a<IMA_MAX_RENDER_SLOT; a++) {
 		if(ima->renders[a]) {
 			RE_FreeRenderResult(ima->renders[a]);

Modified: branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -1527,6 +1527,7 @@
 	}
 }
 
+
 /* ************ READ Brush *************** */
 /* library brush linking after fileread */
 static void lib_link_brush(FileData *fd, Main *main)
@@ -1539,6 +1540,7 @@
 			brush->id.flag -= LIB_NEEDLINK;
 
 			brush->mtex.tex= newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
+			brush->image_icon= newlibadr_us(fd, brush->id.lib, brush->image_icon);
 			brush->clone.image= newlibadr_us(fd, brush->id.lib, brush->clone.image);
 		}
 	}

Modified: branches/soc-2010-jwilkins/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenloader/intern/writefile.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/blenloader/intern/writefile.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -1710,7 +1710,7 @@
 				write_nodetree(wd, ma->nodetree);
 			}
 
-			write_previews(wd, ma->preview);			
+			write_previews(wd, ma->preview);
 		}
 		ma= ma->id.next;
 	}

Modified: branches/soc-2010-jwilkins/source/blender/editors/interface/interface_icons.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/interface/interface_icons.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/editors/interface/interface_icons.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -46,6 +46,7 @@
 
 #include "DNA_screen_types.h"
 #include "DNA_userdef_types.h"
+#include "DNA_brush_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
@@ -978,11 +979,20 @@
 		case ID_IM: /* fall through */
 		case ID_WO: /* fall through */
 		case ID_LA: /* fall through */
-		//case ID_BR: /* fall through */  // XXX:image_icon
 			iconid= BKE_icon_getid(id);
 			/* checks if not exists, or changed */
 			ui_id_icon_render(C, id, preview);
 			break;
+		case ID_BR:
+			{ /* use the image in the brush as the icon */
+			  /* XXX redundancy here can be reduced be rewriting this switch as an if */
+				ID* ima_id = (ID*)((Brush*)id)->image_icon;
+				id = ima_id ? ima_id : id;
+				iconid= BKE_icon_getid(id);
+				/* checks if not exists, or changed */
+				ui_id_icon_render(C, id, preview);
+			}
+			break;
 		default:
 			break;
 	}

Modified: branches/soc-2010-jwilkins/source/blender/editors/render/render_preview.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/render/render_preview.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/editors/render/render_preview.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -291,7 +291,7 @@
 		
 		sce->r.color_mgt_flag = scene->r.color_mgt_flag;
 		/* exception: don't color manage texture previews or icons */
-		if((sp && sp->pr_method==PR_ICON_RENDER) || (id_type == ID_TE  /*|| (id_type==ID_BR && id && ((Brush*)id)->image_icon==NULL)*/)) // XXX:image_icon
+		if((sp && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
 			sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT;
 		if((sp && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
 			sce->r.alphamode= R_ALPHAPREMUL;
@@ -379,8 +379,8 @@
 				}
 			}
 		}
-		else if(id_type==ID_TE /*|| (id_type==ID_BR && id && ((Brush*)id)->image_icon==NULL)*/) {  // XXX:image_icon
-			Tex *tex= /*id_type==ID_BR ? ((Brush*)id)->mtex.tex : */ (Tex*)id;  // XXX:image_icon
+		else if(id_type==ID_TE) {
+			Tex *tex= (Tex*)id;
 			
 			sce->lay= 1<<MA_TEXTURE;
 			
@@ -452,7 +452,7 @@
 	int gamma_correct=0;
 	int offx=0, newx= rect->xmax-rect->xmin, newy= rect->ymax-rect->ymin;
 
-	if (id && (GS(id->name) != ID_TE /* || !(GS(id->name)==ID_BR && ((Brush*)id)->image_icon==NULL)*/)) {  // XXX:image_icon
+	if (id && (GS(id->name) != ID_TE)) {
 		/* exception: don't color manage texture previews - show the raw values */
 		if (sce) gamma_correct = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT;
 	}
@@ -902,7 +902,7 @@
 	}
 	else if(sp->pr_method==PR_NODE_RENDER) {
 		if(idtype == ID_MA) sce->r.scemode |= R_MATNODE_PREVIEW;
-		else if(idtype == ID_TE /* || (idtype==ID_BR && ((Brush*)id)->image_icon==NULL)*/) sce->r.scemode |= R_TEXNODE_PREVIEW; // XXX:image_icon
+		else if(idtype == ID_TE) sce->r.scemode |= R_TEXNODE_PREVIEW;
 		sce->r.mode |= R_OSA;
 	}
 	else {	/* PR_BUTS_RENDER */
@@ -1044,8 +1044,8 @@
 	ID *id= sp->id;
 	short idtype= GS(id->name);
 
-	if(idtype == ID_IM /*|| (idtype == ID_BR && ((Brush*)id)->image_icon)*/) {  // XXX:image_icon
-		Image *ima= /* idtype==ID_BR ? ((Brush*)id)->image_icon : */ (Image*)id;  // XXX:image_icon
+	if(idtype == ID_IM) {
+		Image *ima= (Image*)id;
 		ImBuf *ibuf= NULL;
 		ImageUser iuser;
 

Modified: branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-02 17:37:55 UTC (rev 29874)
@@ -53,8 +53,7 @@
 	struct BrushClone clone;
 	struct CurveMapping *curve;	/* falloff curve */
 	struct MTex mtex;
-	//struct Image *image_icon;  // XXX:image_icon
-	//struct PreviewImage *preview;  // XXX:image_icon
+	struct Image *image_icon;
 
 	int strength_multiplier;		/* increases the strength by a multiplier */
 

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-02 16:50:58 UTC (rev 29873)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-02 17:37:55 UTC (rev 29874)
@@ -585,11 +585,12 @@
 	RNA_def_property_ui_text(prop, "Subract Color", "Color of cursor when subtracting");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
-	//prop= RNA_def_property(srna, "image_icon", PROP_POINTER, PROP_NONE);
-	//RNA_def_property_pointer_sdna(prop, NULL, "image_icon");
-	//RNA_def_property_flag(prop, PROP_EDITABLE);
-	//RNA_def_property_ui_text(prop, "Image Icon", "");
-	//RNA_def_property_update(prop, NC_IMAGE, "rna_Brush_update");
+	prop= RNA_def_property(srna, "image_icon", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "image_icon");
+	RNA_def_property_struct_type(prop, "Image");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Image Icon", "");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list