[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11051] branches/soc-2007-maike/source/ blender/src: Segfault correction on glsl file open error

Miguel Torres Lima torreslima at gmail.com
Mon Jun 25 20:44:32 CEST 2007


Revision: 11051
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11051
Author:   maike
Date:     2007-06-25 20:44:31 +0200 (Mon, 25 Jun 2007)

Log Message:
-----------
Segfault correction on glsl file open error

Modified Paths:
--------------
    branches/soc-2007-maike/source/blender/src/editnode.c
    branches/soc-2007-maike/source/blender/src/glsl_light.c
    branches/soc-2007-maike/source/blender/src/glsl_material.c
    branches/soc-2007-maike/source/blender/src/glsl_node_util.c
    branches/soc-2007-maike/source/blender/src/glsl_util.c
    branches/soc-2007-maike/source/blender/src/glutil.c
    branches/soc-2007-maike/source/blender/src/space.c

Modified: branches/soc-2007-maike/source/blender/src/editnode.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/editnode.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/editnode.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -1460,7 +1460,7 @@
 bNode *node_add_node(SpaceNode *snode, int type, float locx, float locy)
 {
 	bNode *node= NULL, *gnode;
-	
+
 	node_deselectall(snode, 0);
 	
 	if(type>=NODE_GROUP_MENU) {

Modified: branches/soc-2007-maike/source/blender/src/glsl_light.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_light.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/glsl_light.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -135,6 +135,9 @@
   GLSL_List item = glsl_get_light(lamp);
   GLSL_Light light =  (struct GLSL_Light_ *) item->data;
 
+  if(glsl_active() != 1)
+    return;
+
   printf("\n event: %d \n", event);
 
   switch(event)

Modified: branches/soc-2007-maike/source/blender/src/glsl_material.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_material.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/glsl_material.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -91,7 +91,7 @@
 {
   GHashIterator *iter = BLI_ghashIterator_new(treeHash);
   int i;
-  
+ 
   for(i = 0; i < BLI_ghash_size(treeHash); i++, BLI_ghashIterator_step(iter)){
     if(BLI_ghashIterator_getValue(iter) == tree){
       BLI_ghash_lookup_reset(treeHash, BLI_ghashIterator_getKey(iter));
@@ -106,7 +106,8 @@
   if(tree->textured_program)
     tree->textured_program->free(tree->textured_program);
 
-  MEM_freeN(tree);
+  if(tree)
+    MEM_freeN(tree);
   
   printf("\n GLSL MaterialTree removed.\n");
 }
@@ -133,9 +134,11 @@
 
 static void glsl_mat_free(GLSL_Material material, Material *mat)
 {
-  BLI_ghash_lookup_reset(matHash, mat);
-  BLI_ghash_free(material->parent, NULL, NULL);
-  MEM_freeN(material);
+  if(material){
+    BLI_ghash_lookup_reset(matHash, mat);
+    BLI_ghash_free(material->parent, NULL, NULL);
+    MEM_freeN(material);
+  }
   
   printf("\n GLSL Material removed.\n");
 }
@@ -187,11 +190,12 @@
     GHashIterator *iter = BLI_ghashIterator_new(glsl_defmaterial->hash);
     GLSL_Material material = BLI_ghashIterator_getValue(iter);
     
-    BLI_ghashIterator_free(iter);
-    
-    BLI_ghash_free(material->parent, NULL, NULL);
-    MEM_freeN(material);
-    
+    if(material){
+      BLI_ghashIterator_free(iter);
+      
+      BLI_ghash_free(material->parent, NULL, NULL);
+      MEM_freeN(material);
+    }
     glsl_defmaterial->free(glsl_defmaterial);
   }
 }
@@ -534,6 +538,7 @@
   if(glsl_defmaterial->shaded_program)
     glsl_defmaterial->shaded_program->free(glsl_defmaterial->shaded_program);
   glsl_defmaterial->create_programs(glsl_defmaterial);
+  if(glsl_defmaterial->shaded_program)
   glsl_update_material_uniforms(glsl_defmaterial->shaded_program->program, &defmaterial, glsl_defmaterial);
 
   for(i = 0; i < BLI_ghash_size(treeHash); i++, BLI_ghashIterator_step(iter)){

Modified: branches/soc-2007-maike/source/blender/src/glsl_node_util.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_node_util.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/glsl_node_util.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -41,6 +41,7 @@
 
   if((int) program->vertex_shader < 0){
     U.flag &= ~USER_GLSL;
+    glsl_change_state();
     return 0;
   }
   glsl_attach_GLshader(program->program, program->vertex_shader);
@@ -50,6 +51,7 @@
 
   if((int) program->fragment_shader < 0){
     U.flag &= ~USER_GLSL;
+    glsl_change_state();
     glsl_free_GLshader(program->program, program->vertex_shader);
     return 0;
   }

Modified: branches/soc-2007-maike/source/blender/src/glsl_util.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_util.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/glsl_util.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -14,6 +14,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meta_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BKE_material.h"
 #include "BKE_global.h"
@@ -229,8 +230,11 @@
       {
 	char *error = MEM_mallocN(sizeof(char) * (strlen(msg) + strlen(text) +1), "GLSL Error");
 	sprintf(error, "%s%s", text, msg);
-	pupmenu(error);
-	MEM_freeN(error);
+	if(glsl_active() == 1)
+	  pupmenu(error);
+	MEM_freeN(error);    
+	U.flag &= ~USER_GLSL;
+	glsl_change_state();
 	break;
       }
     }

Modified: branches/soc-2007-maike/source/blender/src/glutil.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glutil.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/glutil.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -784,21 +784,28 @@
   glsl_init_ghash();
   glsl_init_defmaterial(&defmaterial);
 
-  if(glsl_active() != 0){
-    for(base= G.scene->base.first; base; base= base->next) {
+  
+  for(base= G.scene->base.first; base; base= base->next) {
+    if(glsl_active() != 0){
       obj = base->object;
       
       if(obj->type == OB_LAMP){
 	glsl_create_light((Lamp *) obj->data, obj);
       }
     }
-    
-    for(base= G.scene->base.first; base; base= base->next) {
+    else
+      glsl_free_all();
+  }
+  
+  for(base= G.scene->base.first; base; base= base->next) {
+    if(glsl_active()){
       obj = base->object;
-
+      
       if(base->lay & G.scene->lay && obj->type != OB_LAMP && obj->type != OB_CAMERA){
 	glsl_query_material(obj);
       }  
     }
+    else
+      glsl_free_all();
   }
 }

Modified: branches/soc-2007-maike/source/blender/src/space.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/space.c	2007-06-25 18:44:28 UTC (rev 11050)
+++ branches/soc-2007-maike/source/blender/src/space.c	2007-06-25 18:44:31 UTC (rev 11051)
@@ -126,6 +126,7 @@
 #include "BIF_toolbox.h"
 #include "BIF_usiblender.h"
 #include "BIF_previewrender.h"
+#include "BIF_glutil.h"
 
 #include "BSE_edit.h"
 #include "BSE_view.h"
@@ -3088,8 +3089,8 @@
 	uiBlock *block;
 	static short cur_light=0;
 	float fac, col[3];
-	short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6;
-	short y2label, y3label, y4label, y5label, y6label;
+	short xpos, ypos, ypostab,  buth, rspace, dx, y1, y2, y3, y4, y5, y6, y7;
+	short y2label, y3label, y4label, y5label, y6label, y7label;
 	short spref, mpref, lpref, smfileselbut;
 	short edgsp, midsp;
 	char naam[32];
@@ -3140,6 +3141,7 @@
 	y4 = ypos+3*(buth+rspace);
 	y5 = ypos+4*(buth+rspace);
 	y6 = ypos+5*(buth+rspace);
+	y7 = ypos+6*(buth+rspace);
 
 
 	y2label = y2-2;		/* adjustments to offset the labels down to align better */
@@ -3147,6 +3149,7 @@
 	y4label = y4-2;
 	y5label = y5-2;
 	y6label = y6-2;
+	y7label = y7-2;
 
 
 	/* set the color to blue and draw the main 'tab' controls */
@@ -3745,28 +3748,37 @@
 			&(U.uiflag), 0, 0, 0, 0, "Hide files/datablocks that start with a dot(.*)");
 
 		uiDefBut(block, LABEL,0,"OpenGL:",
-			(xpos+edgsp+(5*midsp)+(5*mpref)),y6label,mpref,buth,
+			(xpos+edgsp+(5*midsp)+(5*mpref)),y7label,mpref,buth,
 			0, 0, 0, 0, 0, "");
 		uiDefButBitI(block, TOGN, USER_DISABLE_MIPMAP, B_MIPMAPCHANGED, "Mipmaps",
-			(xpos+edgsp+(5*mpref)+(5*midsp)),y5,mpref,buth,
+			(xpos+edgsp+(5*mpref)+(5*midsp)),y6,mpref,buth,
 			&(U.gameflags), 0, 0, 0, 0, "Toggles between mipmap textures on (beautiful) and off (fast)");
 		
 		/* main choices pup: note, it uses collums, and the seperators (%l) then have to fill both halves equally for the menu to work */
 		uiDefButS(block, MENU, B_GLRESLIMITCHANGED, "GL Texture Clamp Off%x0|%l|GL Texture Clamp 8192%x8192|GL Texture Clamp 4096%x4096|GL Texture Clamp 2048%x2048|GL Texture Clamp 1024%x1024|GL Texture Clamp 512%x512|GL Texture Clamp 256%x256|GL Texture Clamp 128%x128",
-													(xpos+edgsp+(5*mpref)+(5*midsp)),y4,mpref,buth, &(U.glreslimit), 0, 0, 0, 0, "Limit the texture size to save graphics memory");
+													(xpos+edgsp+(5*mpref)+(5*midsp)),y5,mpref,buth, &(U.glreslimit), 0, 0, 0, 0, "Limit the texture size to save graphics memory");
 		
 		uiDefButBitI(block, TOG, USER_VERTEX_ARRAYS, 0, "Vertex Arrays",
-			(xpos+edgsp+(5*mpref)+(5*midsp)),y3,mpref,buth,
+			(xpos+edgsp+(5*mpref)+(5*midsp)),y4,mpref,buth,
 			&(U.gameflags), 0, 0, 0, 0, "Toggles between vertex arrays on (less reliable) and off (more reliable)");
 
 		uiDefButI(block, NUM, 0, "Time Out ",
-			(xpos+edgsp+(5*mpref)+(5*midsp)), y2, mpref, buth, 
+			(xpos+edgsp+(5*mpref)+(5*midsp)), y3, mpref, buth, 
 			&U.textimeout, 0.0, 3600.0, 30, 2, "Time since last access of a GL texture in seconds after which it is freed. (Set to 0 to keep textures allocated)");
 		uiDefButI(block, NUM, 0, "Collect Rate ",
-			(xpos+edgsp+(5*mpref)+(5*midsp)), y1, mpref, buth, 
+			(xpos+edgsp+(5*mpref)+(5*midsp)), y2, mpref, buth, 
 			&U.texcollectrate, 1.0, 3600.0, 30, 2, "Number of seconds between each run of the GL texture garbage collector.");
 
+		if(has_glsl_support()){
+		            uiDefButBitI(block, TOG, USER_GLSL, B_GLSLCHANGED, "GLSL Preview",
+			       (xpos+edgsp+(5*mpref)+(5*midsp)),y1, mpref, buth,
+			       &(U.flag), 0, 0, 0, 0, "Toggles between GLSL preview on the Viewport3D on and off");
+		}
+		else{
 
+		}
+		
+
 		uiDefBut(block, LABEL,0,"Audio mixing buffer:",
 			(xpos+edgsp+(2*midsp)+(2*mpref)),y3label,mpref,buth,
 			0, 0, 0, 0, 0, "");





More information about the Bf-blender-cvs mailing list