Changeset 1310


Ignore:
Timestamp:
09/02/11 23:43:36 (21 months ago)
Author:
philmoz
Message:

Fixes for menu / font problems reported:

  • crash if changing menu font multiple times in quick succession.
  • crash in the script menu if using a large font and the loaded script has a very long title.
  • fixed potential timing/cache issue with the font loading code.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/gui_fselect.c

    r1302 r1310  
    10521052                    gui_fselect_free_data(); 
    10531053                    gui_fselect_marked_free_data(); 
     1054                    if (fselect_on_select)  
     1055                        fselect_on_select(selected_file); 
    10541056                    gui_set_mode(gui_fselect_mode_old); 
    10551057                    draw_restore(); 
    1056                     if (fselect_on_select)  
    1057                         fselect_on_select(selected_file); 
    10581058                } 
    10591059            } 
     
    10781078            gui_fselect_free_data(); 
    10791079            gui_fselect_marked_free_data(); 
     1080            if (fselect_on_select)  
     1081                fselect_on_select(NULL); 
    10801082            gui_set_mode(gui_fselect_mode_old); 
    10811083            draw_restore(); 
    1082             if (fselect_on_select)  
    1083                 fselect_on_select(NULL); 
    1084             break; 
    1085     } 
    1086 } 
    1087  
    1088 //------------------------------------------------------------------- 
     1084            break; 
     1085    } 
     1086} 
     1087 
     1088//------------------------------------------------------------------- 
  • trunk/core/gui_menu.c

    r1299 r1310  
    3232 
    3333static int          count; 
    34 static coord        x, y, w, num_lines; 
     34static int          x, y; 
     35static int          w, num_lines; 
    3536static int          len_bool, len_int, len_enum, len_space, len_br1, len_br2, cl_rect; 
    3637static int          int_incr, incr_modified; 
     
    701702                if (lang_str(curr_menu->menu[imenu].text)[0]) 
    702703                    sprintf(tbuf," %s ",lang_str(curr_menu->menu[imenu].text)); 
    703  
    704                 j = rbf_str_width(lang_str(curr_menu->menu[imenu].text)); 
    705                 xx += ((int)w - j - len_space*2) >> 1; 
    706  
    707                 draw_filled_rect(x+len_space, yy, xx-1, yy+rbf_font_height()/2-1, MAKE_COLOR(cl>>8, cl>>8)); 
    708                 draw_line(x+len_space, yy+rbf_font_height()/2, xx-1, yy+rbf_font_height()/2, cl); 
    709                 draw_filled_rect(x+len_space, yy+rbf_font_height()/2+1, xx-1, yy+rbf_font_height()-1, MAKE_COLOR(cl>>8, cl>>8)); 
    710  
    711                 if (j) xx += rbf_draw_string(xx, yy, tbuf, cl); 
    712  
    713                 draw_filled_rect(xx, yy, x+w-len_space-1, yy+rbf_font_height()/2-1, MAKE_COLOR(cl>>8, cl>>8)); 
    714                 draw_line(xx, yy+rbf_font_height()/2, x+w-1-len_space, yy+rbf_font_height()/2, cl); 
    715                 draw_filled_rect(xx, yy+rbf_font_height()/2+1, x+w-len_space-1, yy+rbf_font_height()-1, MAKE_COLOR(cl>>8, cl>>8)); 
     704                else 
     705                    tbuf[0] = 0; 
     706 
     707                j = rbf_str_width(tbuf); 
     708                xx += ((w - j) >> 1); 
     709 
     710                if (xx > (x + len_space)) 
     711                { 
     712                    draw_filled_rect(x+len_space, yy, xx-1, yy+rbf_font_height()/2-1, MAKE_COLOR(cl>>8, cl>>8)); 
     713                    draw_line(x+len_space, yy+rbf_font_height()/2, xx-1, yy+rbf_font_height()/2, cl); 
     714                    draw_filled_rect(x+len_space, yy+rbf_font_height()/2+1, xx-1, yy+rbf_font_height()-1, MAKE_COLOR(cl>>8, cl>>8)); 
     715                } 
     716                else 
     717                { 
     718                    xx = x; 
     719                } 
     720 
     721                if (j) xx += rbf_draw_clipped_string(xx, yy, tbuf, cl, 0, w); 
     722 
     723                if (xx < (x+w-len_space)) 
     724                { 
     725                    draw_filled_rect(xx, yy, x+w-len_space-1, yy+rbf_font_height()/2-1, MAKE_COLOR(cl>>8, cl>>8)); 
     726                    draw_line(xx, yy+rbf_font_height()/2, x+w-1-len_space, yy+rbf_font_height()/2, cl); 
     727                    draw_filled_rect(xx, yy+rbf_font_height()/2+1, x+w-len_space-1, yy+rbf_font_height()-1, MAKE_COLOR(cl>>8, cl>>8)); 
     728                } 
    716729 
    717730                rbf_draw_char(x+w-len_space, yy, ' ', cl); 
  • trunk/include/font.h

    r875 r1310  
    3636extern int rbf_draw_string(int x, int y, const char *str, color cl); 
    3737extern int rbf_draw_string_c(int x, int y, const char *str, color cl1, int c, color cl2); 
     38extern int rbf_draw_clipped_string(int x, int y, const char *str, color cl, int l, int maxlen); 
    3839extern int rbf_draw_string_len(int x, int y, int len, const char *str, color cl); 
    3940extern int rbf_draw_string_right_len(int x, int y, int len, const char *str, color cl); 
  • trunk/lib/font/rbf_font.c

    r1186 r1310  
    66 
    77//------------------------------------------------------------------- 
    8 #define RBF_MAX_NAME       64 
    9  
     8#define RBF_MAX_NAME        64 
     9#define UBUFFER_SIZE        256 // Amount of uncached memory to allocate for file reading 
    1010//------------------------------------------------------------------- 
    1111static unsigned int RBF_HDR_MAGIC1 = 0x0DF00EE0; 
     
    5050    // Current size of the cTable data 
    5151    int cTableSize; 
    52     struct _font *uncached_font;      // address of font in uncached memory (for passing to ufree & read) 
    53     char *uncached_cTable;            // address of cTable in uncached memory (for passing to ufree & read) 
     52    int cTableSizeMax;                // max size of cTable (max size currently allocated) 
    5453} font; 
    5554 
     55static unsigned char *ubuffer = 0;                  // uncached memory buffer for reading font data from SD card 
    5656static font *rbf_symbol_font = 0, *rbf_font = 0; 
    5757static int rbf_codepage = FONT_CP_WIN;  
     
    6060 
    6161font *new_font() { 
    62     // allocate font from uncached memory 
    63     font *f = umalloc(sizeof(font)); 
     62    // allocate font from cached memory 
     63    font *f = malloc(sizeof(font)); 
    6464    if (f) { 
    65         memset(f,0,sizeof(font));      // wipe memory (use uncached address to avoid conflict with read & caching) 
    66         f->uncached_font = f;          // save uncached memory address 
    67         // return address in cached memory for faster font rendering 
    68         return (font*)((int)f & ~CAM_UNCACHED_BIT); 
     65        memset(f,0,sizeof(font));      // wipe memory 
     66        // return address in cached memory 
     67        return f; 
    6968    } 
    7069 
     
    7877    if (rbf_font == 0) rbf_font = new_font(); 
    7978    if (rbf_symbol_font == 0) rbf_symbol_font = new_font(); 
     79 
     80    // allocate uncached memory buffer for reading 
     81    ubuffer = umalloc(UBUFFER_SIZE); 
    8082} 
    8183 
     
    9496    // See if it the existing cTable data is large enough to hold the new font data 
    9597    // If not free it so new memory will be allocated 
    96     if ((f->cTable != 0) && (f->cTableSize < (f->charCount*f->hdr.charSize))) { 
    97         ufree(f->uncached_cTable);    // free the memory using the uncached address 
     98    if ((f->cTable != 0) && (f->cTableSizeMax < (f->charCount*f->hdr.charSize))) { 
     99        free(f->cTable);              // free the memory 
    98100        f->cTable = 0;                // clear pointer so new memory is allocated 
    99         f->uncached_cTable = 0; 
     101        f->cTableSizeMax = 0; 
    100102    } 
    101103 
    102104    // Allocated memory if needed 
    103105    if (f->cTable == 0 && !f->usingFont8x16) { 
    104         // Allocate memory from uncached pool 
    105         f->uncached_cTable = umalloc(f->charCount*f->hdr.charSize); 
    106         // Store cached memory address 
    107         f->cTable = (char*)((int)f->uncached_cTable & ~CAM_UNCACHED_BIT); 
     106        // Allocate memory from cached pool 
     107        f->cTable = malloc(f->charCount*f->hdr.charSize); 
    108108 
    109109        // save size 
    110110        f->cTableSize = f->charCount*f->hdr.charSize; 
     111        if (f->cTableSizeMax == 0) f->cTableSizeMax = f->cTableSize;    // Save actual size allocated 
    111112    } 
    112113} 
     
    146147} 
    147148//------------------------------------------------------------------- 
     149// Read data from SD file using uncached buffer and copy to cached 
     150// font memory 
     151int font_read(int fd, unsigned char *dest, int len) 
     152{ 
     153    // Return actual bytes read 
     154    int bytes_read = 0; 
     155 
     156    if (ubuffer) 
     157    { 
     158        // Read file in UBUFFER_SIZE blocks 
     159        while (len) 
     160        { 
     161            // Calc size of next block to read = min(UBUFFER_SIZE, len) 
     162            int to_read = UBUFFER_SIZE; 
     163            if (to_read > len) to_read = len; 
     164 
     165            // Read block and copy to dest 
     166            bytes_read += read(fd, ubuffer, to_read); 
     167            memcpy(dest, ubuffer, to_read); 
     168 
     169            // Increment dest pointer, decrement len left to read 
     170            dest += to_read; 
     171            len -= to_read; 
     172        } 
     173    } 
     174 
     175    return bytes_read; 
     176} 
     177//------------------------------------------------------------------- 
    148178// Load from from file. If maxchar != 0 limit charLast (for symbols) 
    149 // Note: pass the uncached font address to this function 
    150179int rbf_font_load(char *file, font* f, int maxchar) 
    151180{ 
     
    162191    if (fd >= 0) { 
    163192        // read header 
    164         i = read(fd, &f->hdr, sizeof(font_hdr)); 
     193        i = font_read(fd, (unsigned char*)&f->hdr, sizeof(font_hdr)); 
    165194 
    166195        // check size read is correct and magic numbers are valid 
     
    173202            alloc_cTable(f); 
    174203 
    175             // read width table (using uncached memory address) 
     204            // read width table (using uncached buffer) 
    176205            lseek(fd, f->hdr._wmapAddr, SEEK_SET); 
    177             read(fd, &f->wTable[f->hdr.charFirst], f->charCount); 
    178  
    179             // read cTable data (using uncached memory address) 
     206            font_read(fd, (unsigned char*)&f->wTable[f->hdr.charFirst], f->charCount); 
     207 
     208            // read cTable data (using uncached buffer) 
    180209            lseek(fd, f->hdr._cmapAddr, SEEK_SET); 
    181             read(fd, f->uncached_cTable, f->charCount*f->hdr.charSize); 
     210            font_read(fd, (unsigned char*)f->cTable, f->charCount*f->hdr.charSize); 
    182211 
    183212            close(fd); 
     
    198227    init_fonts(); 
    199228    // Load font 
    200     return rbf_font_load(file, rbf_font->uncached_font, 0); 
     229    return rbf_font_load(file, rbf_font, 0); 
    201230} 
    202231 
     
    207236    init_fonts(); 
    208237    // Load font 
    209     return rbf_font_load(file, rbf_symbol_font->uncached_font, maxSymbols+32); 
     238    return rbf_font_load(file, rbf_symbol_font, maxSymbols+32); 
    210239} 
    211240 
Note: See TracChangeset for help on using the changeset viewer.