From 2b5f8c94d04a985959553044498471f68a952b16 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Mar 2011 22:24:47 +0000 Subject: changes to icon loading - look for icons in datafiles/icons (was looking in datafiles) - was loading all images in datafiles/ on startup to check if they were the correct icon size, commented this since its unnecessary disk overhead on startup & images are checked for correctness when used anyway. when running blender from the source dir would load splash.png every time. also add missing NULL pointer check if the icon couldn't be loaded and ensure no buffer overflow check on icon path creation. --- source/blender/editors/interface/interface_icons.c | 56 ++++++++++------------ 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'source/blender/editors/interface/interface_icons.c') diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 4a36f34d468..03c50d213c1 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -514,18 +514,14 @@ static void init_internal_icons(void) char iconfilestr[FILE_MAXDIR+FILE_MAXFILE]; if ((btheme!=NULL) && btheme->tui.iconfile[0]) { - char *datadir= BLI_get_folder(BLENDER_DATAFILES, NULL); - if (datadir) { - BLI_make_file_string("/", iconfilestr, datadir, btheme->tui.iconfile); - - if (BLI_exists(iconfilestr)) { - bbuf = IMB_loadiffname(iconfilestr, IB_rect); - if(bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H) { - if (G.f & G_DEBUG) - printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr); - IMB_freeImBuf(bbuf); - bbuf= NULL; - } + char *icondir= BLI_get_folder(BLENDER_DATAFILES, "icons"); + if (icondir) { + BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); + bbuf = IMB_loadiffname(iconfilestr, IB_rect); /* if the image is missing bbuf will just be NULL */ + if(bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) { + printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr); + IMB_freeImBuf(bbuf); + bbuf= NULL; } } } @@ -597,31 +593,23 @@ static void init_internal_icons(void) static void init_iconfile_list(struct ListBase *list) { IconFile *ifile; - ImBuf *bbuf= NULL; struct direntry *dir; int restoredir = 1; /* restore to current directory */ int totfile, i, index=1; - int ifilex, ifiley; - char icondirstr[FILE_MAX]; - char iconfilestr[FILE_MAX+16]; /* allow 256 chars for file+dir */ + const char *icondir; char olddir[FILE_MAX]; - char *datadir= NULL; list->first = list->last = NULL; - datadir = BLI_get_folder(BLENDER_DATAFILES, NULL); - - if (!datadir) return; + icondir = BLI_get_folder(BLENDER_DATAFILES, "icons"); - BLI_make_file_string("/", icondirstr, datadir, ""); - - if(BLI_exists(icondirstr)==0) + if(icondir==NULL) return; /* since BLI_getdir changes the current working directory, restore it back to old value afterwards */ if(!BLI_getwdN(olddir, sizeof(olddir))) restoredir = 0; - totfile = BLI_getdir(icondirstr, &dir); + totfile = BLI_getdir(icondir, &dir); if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */ for(i=0; ix; @@ -650,8 +639,11 @@ static void init_iconfile_list(struct ListBase *list) } /* bad size or failed to load */ - if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) + if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) { + printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley); continue; + } +#endif /* removed */ /* found a potential icon file, so make an entry for it in the cache list */ ifile = MEM_callocN(sizeof(IconFile), "IconFile"); -- cgit v1.2.3