[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21558] branches/blender2.5/blender/source /blender/editors/space_text/text_draw.c: Drawing a string longer then 255 chars wasnt working.

Campbell Barton ideasman42 at gmail.com
Mon Jul 13 13:41:24 CEST 2009


Revision: 21558
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21558
Author:   campbellbarton
Date:     2009-07-13 13:41:24 +0200 (Mon, 13 Jul 2009)

Log Message:
-----------
Drawing a string longer then 255 chars wasnt working.

changes to flatten_string_append(...), probably only brecht is interested.
- It was copying from the old malloc'd buffer but never the fixed buffer - the reason >255 length strings didnt render.
- on first malloc for the FlatString allocate 512 rather then 256 chars since the fixed string is 256 chars.
- if the char was '\0' fs->pos was set to 0, not sure why since char cant be '\0' because of the loop that calls flatten_string_append, removed.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/space_text/text_draw.c

Modified: branches/blender2.5/blender/source/blender/editors/space_text/text_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_text/text_draw.c	2009-07-13 11:04:18 UTC (rev 21557)
+++ branches/blender2.5/blender/source/blender/editors/space_text/text_draw.c	2009-07-13 11:41:24 UTC (rev 21558)
@@ -109,22 +109,18 @@
 {
 	if(fs->pos>=fs->len && fs->pos>=sizeof(fs->fixedbuf)-1) {
 		char *nbuf; int *naccum;
-		int olen= fs->len;
-		
-		if(olen) fs->len*= 2;
-		else fs->len= 256;
-		
+		if(fs->len) fs->len*= 2;
+		else fs->len= sizeof(fs->fixedbuf) * 2;
+
 		nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf");
 		naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum");
+
+		memcpy(nbuf, fs->buf, fs->pos);
+		memcpy(naccum, fs->accum, fs->pos);
 		
-		if(olen) {
-			memcpy(nbuf, fs->buf, olen);
-			memcpy(naccum, fs->accum, olen);
-			
-			if(fs->buf != fs->fixedbuf) {
-				MEM_freeN(fs->buf);
-				MEM_freeN(fs->accum);
-			}
+		if(fs->buf != fs->fixedbuf) {
+			MEM_freeN(fs->buf);
+			MEM_freeN(fs->accum);
 		}
 		
 		fs->buf= nbuf;
@@ -134,8 +130,7 @@
 	fs->buf[fs->pos]= c;	
 	fs->accum[fs->pos]= accum;
 	
-	if(c==0) fs->pos= 0;
-	else fs->pos++;
+	fs->pos++;
 }
 
 int flatten_string(SpaceText *st, FlattenString *fs, char *in)
@@ -1336,6 +1331,7 @@
 				UI_ThemeColor(TH_TEXT);
 
 			sprintf(linenr, "%d", i + linecount + 1);
+			/* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
 			text_font_draw(st, TXT_OFFSET - 7, y, linenr);
 
 			UI_ThemeColor(TH_TEXT);





More information about the Bf-blender-cvs mailing list