diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-12-22 20:16:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-12-22 20:16:06 +0300 |
commit | 6f730601af1e169bb80a2f73839dea8091211b5c (patch) | |
tree | 2fe7683a0ebbf8e0ffd6a90651c680f90336cb55 /source/blender/src | |
parent | a000473d9d9c406b69caa55acb9e8394e5b2fcc5 (diff) |
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.
Diffstat (limited to 'source/blender/src')
-rw-r--r-- | source/blender/src/drawtext.c | 62 | ||||
-rw-r--r-- | source/blender/src/header_text.c | 82 |
2 files changed, 85 insertions, 59 deletions
diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c index 0b33a4df5fc..b4026746a35 100644 --- a/source/blender/src/drawtext.c +++ b/source/blender/src/drawtext.c @@ -167,15 +167,13 @@ void free_txt_data(void) { 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 @@ static int render_string (char *in) { 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 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra 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 @@ static void set_cursor_to_pos (SpaceText *st, int x, int y, int sel) 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 @@ void drawtextspace(ScrArea *sa, void *spacedata) 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 @@ void drawtextspace(ScrArea *sa, void *spacedata) if(st->showsyntax) { if (tmp && !tmp->format) { - get_format_string(); + get_format_string(st); } } @@ -1080,13 +1079,12 @@ void pop_space_text (SpaceText *st) 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 @@ void add_text_fs(char *file) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } } 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) 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 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } } } - 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 @@ void convert_tabs (struct SpaceText *st, int tab) //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++; diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c index 04c354fb2b1..728edc76a9c 100644 --- a/source/blender/src/header_text.c +++ b/source/blender/src/header_text.c @@ -79,13 +79,12 @@ 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: @@ -132,7 +131,7 @@ void do_text_buttons(unsigned short event) 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 @@ void do_text_buttons(unsigned short event) 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 @@ static uiBlock *text_template_scriptsmenu (void *args_unused) /* 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 @@ static void do_text_filemenu(void *arg, int event) 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 @@ static void do_text_filemenu(void *arg, int event) /* 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 @@ static void do_text_editmenu(void *arg, int event) 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 @@ static void do_text_editmenu(void *arg, int event) /* 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 @@ static void do_text_editmenu_viewmenu(void *arg, int event) /* 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; + if (st==NULL || st->spacetype != SPACE_TEXT) return; + + text = st->text; + switch(event) { case 1: txt_sel_all(text); @@ -464,10 +479,14 @@ static void do_text_editmenu_selectmenu(void *arg, int event) /* action executed after clicking in Format menu */ static void do_text_formatmenu(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 3: if (txt_has_sel(text)) { @@ -490,7 +509,7 @@ static void do_text_formatmenu(void *arg, int event) if ( txt_has_sel(text)) { txt_order_cursors(text); comment(text); - if (st->showsyntax) get_format_string(); + if (st->showsyntax) get_format_string(st); break; } break; @@ -498,7 +517,7 @@ static void do_text_formatmenu(void *arg, int event) if ( txt_has_sel(text)) { txt_order_cursors(text); uncomment(text); - if (st->showsyntax) get_format_string(); + if (st->showsyntax) get_format_string(st); break; } break; @@ -552,7 +571,9 @@ static uiBlock *text_editmenu_selectmenu(void *arg_unused) void do_text_formatmenu_convert(void *arg, int event) { - SpaceText *st= curarea->spacedata.first; + SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */ + + if (st==NULL || st->spacetype != SPACE_TEXT) return; switch(event) { case 1: convert_tabs(st, 0); break; @@ -611,8 +632,11 @@ static uiBlock *text_formatmenu(void *arg_unused) /* action executed after clicking in Object to 3d Sub Menu */ void do_text_editmenu_to3dmenu(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; + if (st==NULL || st->spacetype != SPACE_TEXT) return; + + text = st->text; switch(event) { case 1: txt_export_to_object(text); break; @@ -680,7 +704,7 @@ static uiBlock *text_editmenu(void *arg_unused) /* File menu */ static uiBlock *text_filemenu(void *arg_unused) { - SpaceText *st= curarea->spacedata.first; + SpaceText *st= curarea->spacedata.first; /* bad but cant pass as an arg here */ Text *text= st->text; uiBlock *block; short yco= 0, menuwidth=120; @@ -728,11 +752,13 @@ void text_buttons(void) { uiBlock *block; SpaceText *st= curarea->spacedata.first; - Text *text= st->text; + Text *text; short xco, xmax; char naam[256]; - if (!st || st->spacetype != SPACE_TEXT) return; + if (st==NULL || st->spacetype != SPACE_TEXT) return; + + text = st->text; sprintf(naam, "header %d", curarea->headwin); block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin); |