[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12975] trunk/blender/source/blender: Text draw assumed curarea->spacedata. first was always a text space - which in some cases is not correct.

Campbell Barton ideasman42 at gmail.com
Sat Dec 22 18:16:07 CET 2007


Revision: 12975
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12975
Author:   campbellbarton
Date:     2007-12-22 18:16:06 +0100 (Sat, 22 Dec 2007)

Log Message:
-----------
Text draw assumed curarea->spacedata.first was always a text space - which in some cases is not correct.
This fixes a crash where python changing screens then raising an error would cause a crash.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_drawtext.h
    trunk/blender/source/blender/src/drawtext.c
    trunk/blender/source/blender/src/header_text.c

Modified: trunk/blender/source/blender/include/BIF_drawtext.h
===================================================================
--- trunk/blender/source/blender/include/BIF_drawtext.h	2007-12-22 12:05:27 UTC (rev 12974)
+++ trunk/blender/source/blender/include/BIF_drawtext.h	2007-12-22 17:16:06 UTC (rev 12975)
@@ -47,7 +47,7 @@
 void free_txt_data(void);
 void pop_space_text(struct SpaceText *st);
 
-void get_format_string(void);
+void get_format_string(struct SpaceText *st);
 void do_brackets(void);
 
 #endif

Modified: trunk/blender/source/blender/src/drawtext.c
===================================================================
--- trunk/blender/source/blender/src/drawtext.c	2007-12-22 12:05:27 UTC (rev 12974)
+++ trunk/blender/source/blender/src/drawtext.c	2007-12-22 17:16:06 UTC (rev 12975)
@@ -167,15 +167,13 @@
 	if (temp_char_accum) MEM_freeN(temp_char_accum);	
 }
 
-static int render_string (char *in) {
-	SpaceText *st= curarea->spacedata.first;
+static int render_string (SpaceText *st, char *in) {
 	int r = 0, i = 0;
 	
 	while(*in) {
 		if (*in=='\t') {
 			if (temp_char_pos && *(in-1)=='\t') i= st->tabnumber;
 			else if (st->tabnumber > 0) i= st->tabnumber - (temp_char_pos%st->tabnumber);
-
 			while(i--) temp_char_write(' ', r);
 		} else temp_char_write(*in, r);
 
@@ -188,9 +186,8 @@
 	return r;
 }
 
-void get_format_string(void) 
+void get_format_string(SpaceText *st) 
 {
-	SpaceText *st = curarea->spacedata.first;
 	Text *text = st->text;
 	TextLine *tmp;
 	char *in_line;
@@ -538,7 +535,7 @@
 	char *in;
 	int *acc;
 
-	w= render_string(str);
+	w= render_string(st, str);
 	if(w<cshift ) return 0; /* String is shorter than shift */
 	
 	in= temp_char_buf+cshift;
@@ -630,7 +627,7 @@
 	if (x<0) x= 0;
 	x = (x/spacetext_get_fontwidth(st)) + st->left;
 	
-	w= render_string((*linep)->line);
+	w= render_string(st, (*linep)->line);
 	if(x<w) *charp= temp_char_accum[x];
 	else *charp= (*linep)->len;
 	
@@ -996,6 +993,8 @@
 	float col[3];
 	int linecount = 0;
 
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
 	BIF_GetThemeColor3fv(TH_BACK, col);
 	glClearColor(col[0], col[1], col[2], 0.0);
 	glClear(GL_COLOR_BUFFER_BIT);
@@ -1030,7 +1029,7 @@
 	
 	if(st->showsyntax) {
 		if (tmp && !tmp->format) {
-			get_format_string();
+			get_format_string(st);
 		}
 	}
 	
@@ -1080,13 +1079,12 @@
 	if (st->left <0) st->left= 0;
 }
 
-void add_text_fs(char *file) 
+void add_text_fs(char *file) /* bad but cant pass an as arg here */
 {
 	SpaceText *st= curarea->spacedata.first;
 	Text *text;
 
-	if (!st) return;
-	if (st->spacetype != SPACE_TEXT) return;
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
 
 	text= add_text(file);
 
@@ -1094,7 +1092,7 @@
 
 	st->top= 0;
 
-	if (st->showsyntax) get_format_string();
+	if (st->showsyntax) get_format_string(st);
 	allqueue(REDRAWTEXT, 0);
 	allqueue(REDRAWHEADERS, 0);	
 }
@@ -1466,9 +1464,11 @@
 	short val= evt->val;
 	char ascii= evt->ascii;
 	SpaceText *st= curarea->spacedata.first;
-	Text *text= st->text;
+	Text *text;
 	int do_draw=0, p;
-
+	
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
 	/* smartass code to prevent the CTRL/ALT events below from not working! */
 	if(G.qual & (LR_ALTKEY|LR_CTRLKEY))
 		if(!ispunct(ascii)) 
@@ -1580,7 +1580,7 @@
 		}
 	} else if (ascii) {
 		if (txt_add_char(text, ascii)) {
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			pop_space_text(st);
 			do_draw= 1;
 		}
@@ -1612,11 +1612,11 @@
 				txt_order_cursors(text);
 				uncomment(text);
 				do_draw = 1;
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				break;
 			} else if (G.qual == LR_CTRLKEY) {
 				txt_delete_char(text);
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				do_draw= 1;
 				pop_space_text(st);
 			}
@@ -1634,7 +1634,7 @@
 					break;
 				case 2:
 					txt_paste(text);
-					if (st->showsyntax) get_format_string();
+					if (st->showsyntax) get_format_string(st);
 					do_draw= 1;
 					break;
 				case 3:
@@ -1722,7 +1722,7 @@
 				if (okee("Reopen text")) {
 					if (!reopen_text(text))
 						error("Could not reopen file");
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				}
 				do_draw= 1;	
 			}
@@ -1766,7 +1766,7 @@
 			}
 			if (G.qual == LR_ALTKEY) {
 				txt_do_undo(text);
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				do_draw= 1;
 			}
 			break; /* BREAK U */
@@ -1800,7 +1800,7 @@
 					txt_paste_clipboard(text);
 				else
 					txt_paste(text);
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				do_draw= 1;	
 				pop_space_text(st);
 			}
@@ -1808,7 +1808,7 @@
 		case XKEY:
 			if (G.qual == LR_ALTKEY || G.qual == LR_CTRLKEY) {
 				txt_cut_sel(text);
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				do_draw= 1;	
 				pop_space_text(st);
 			}
@@ -1820,7 +1820,7 @@
 				} else {
 					txt_do_undo(text);
 				}
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				do_draw= 1;
 			}
 			break;
@@ -1839,7 +1839,7 @@
 					txt_add_char(text, '\t');
 				}
 			}
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			pop_space_text(st);
 			do_draw= 1;
 			st->currtab_set = setcurr_tab(text);
@@ -1858,20 +1858,20 @@
 					}
 				}
 			}
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			do_draw= 1;
 			pop_space_text(st);
 			break;
 		case BACKSPACEKEY:
 			txt_backspace_char(text);
 			set_tabs(text);
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			do_draw= 1;
 			pop_space_text(st);
 			break;
 		case DELKEY:
 			txt_delete_char(text);
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			do_draw= 1;
 			pop_space_text(st);
 			st->currtab_set = setcurr_tab(text);
@@ -2138,18 +2138,18 @@
 	//first convert to all space, this make it alot easier to convert to tabs because there is no mixtures of ' ' && '\t'
 	while(tmp) {
 		check_line = tmp->line;
-		new_line = MEM_mallocN(render_string(check_line)+1, "Converted_Line");
-		format = MEM_mallocN(render_string(check_line)+1, "Converted_Syntax_format");
+		new_line = MEM_mallocN(render_string(st, check_line)+1, "Converted_Line");
+		format = MEM_mallocN(render_string(st, check_line)+1, "Converted_Syntax_format");
 		j = 0;
 		for (a=0; a < strlen(check_line); a++) { //foreach char in line
 			if(check_line[a] == '\t') { //checking for tabs
 				//get the number of spaces this tabs is showing
 				//i dont like doing it this way but will look into it later
 				new_line[j] = '\0';
-				number = render_string(new_line);
+				number = render_string(st, new_line);
 				new_line[j] = '\t';
 				new_line[j+1] = '\0';
-				number = render_string(new_line)-number;
+				number = render_string(st, new_line)-number;
 				for(extra = 0; extra < number; extra++) {
 					new_line[j] = ' ';
 					j++;

Modified: trunk/blender/source/blender/src/header_text.c
===================================================================
--- trunk/blender/source/blender/src/header_text.c	2007-12-22 12:05:27 UTC (rev 12974)
+++ trunk/blender/source/blender/src/header_text.c	2007-12-22 17:16:06 UTC (rev 12975)
@@ -79,14 +79,13 @@
 
 void do_text_buttons(unsigned short event)
 {
-	SpaceText *st= curarea->spacedata.first;
+	SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
 	ID *id, *idtest;
 	int nr= 1;
 	Text *text;
-		
-	if (!st) return;
-	if (st->spacetype != SPACE_TEXT) return;
 	
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
 	switch (event) {
 	case B_TEXTBROWSE:
 		if (st->menunr==-2) {
@@ -132,7 +131,7 @@
 				st->top= 0;
 				
 				pop_space_text(st);
-				if (st->showsyntax) get_format_string();
+				if (st->showsyntax) get_format_string(st);
 				allqueue(REDRAWTEXT, 0);
 				allqueue(REDRAWHEADERS, 0);
 			}
@@ -230,13 +229,13 @@
 
 		break;
 	case B_TAB_NUMBERS:
-		if (st->showsyntax) get_format_string();
+		if (st->showsyntax) get_format_string(st);
 		allqueue(REDRAWTEXT, 0);
 		allqueue(REDRAWHEADERS, 0);
 		break;
 	case B_SYNTAX:
 		if (st->showsyntax) {
-			get_format_string();
+			get_format_string(st);
 		}
 		allqueue(REDRAWTEXT, 0);
 		allqueue(REDRAWHEADERS, 0);
@@ -278,10 +277,14 @@
 /* action executed after clicking in File menu */
 static void do_text_filemenu(void *arg, int event)
 {
-	SpaceText *st= curarea->spacedata.first;
-	Text *text= st->text;
+	SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
+	Text *text;
 	ScrArea *sa;
-
+	
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
+	text= st->text;
+	
 	switch(event) {
 	case 1:
 		st->text= add_empty_text( "Text" );
@@ -300,7 +303,7 @@
 				if (!reopen_text(text)) {
 					error("Could not reopen file");
 				}
-			if (st->showsyntax) get_format_string();
+			if (st->showsyntax) get_format_string(st);
 			}
 		break;
 	case 5:
@@ -361,10 +364,14 @@
 /* action executed after clicking in Edit menu */
 static void do_text_editmenu(void *arg, int event)
 {
-	SpaceText *st= curarea->spacedata.first;
-	Text *text= st->text;
+	SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
+	Text *text;
 	ScrArea *sa;
 	
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
+	text= st->text;
+	
 	switch(event) {
 	case 1:
 		txt_do_undo(text);
@@ -381,7 +388,7 @@
 		break;
 	case 5:
 		txt_paste(text);
-		if (st->showsyntax) get_format_string();
+		if (st->showsyntax) get_format_string(st);
 		break;
 	case 6:
 		txt_print_cutbuffer();
@@ -410,10 +417,14 @@
 /* action executed after clicking in View menu */
 static void do_text_editmenu_viewmenu(void *arg, int event)
 {
-	SpaceText *st= curarea->spacedata.first;
-	Text *text= st->text;
+	SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
+	Text *text;
 	ScrArea *sa;
 	
+	if (st==NULL || st->spacetype != SPACE_TEXT) return;
+	
+	text = st->text;
+	
 	switch(event) {
 		case 1:
 			txt_move_bof(text, 0);
@@ -438,10 +449,14 @@
 /* action executed after clicking in Select menu */
 static void do_text_editmenu_selectmenu(void *arg, int event)
 {
-	SpaceText *st= curarea->spacedata.first;
-	Text *text= st->text;
+	SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */
+	Text *text;
 	ScrArea *sa;
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list