From: Holger Schemel Date: Fri, 31 May 2002 15:41:42 +0000 (+0200) Subject: rnd-20020531-1-src X-Git-Tag: 2.1.0^2~10 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7891415ca10eb882506eaaa3bca720ec75723a0e;p=rocksndiamonds.git rnd-20020531-1-src --- diff --git a/CHANGES b/CHANGES index 433c6048..1e79605f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ Release Version 2.1.0 [XX XXX XXXX] ----------------------------------- + - fixed memory leak in image loading code - added Boulderdash style "snap-pushing" (thanks to Achim Härtel) - bug fixed that prevented walking through tubes when gravity on - enhanced sound system (especially regarding stereo and loop sounds) diff --git a/src/libgame/image.c b/src/libgame/image.c index 9b89100b..62b8fed3 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -245,6 +245,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, bluestep = 256 / bluecolors; redbottom = greenbottom = bluebottom = 0; redtop = greentop = bluetop = 0; + for (a=0; amap_entries; a++) { if (redbottom < 256) @@ -275,10 +276,12 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, /* something completely unexpected happened */ fprintf(stderr, "Image_to_Pixmap: XAllocColor failed on a TrueColor/Directcolor visual\n"); + free(redvalue); free(greenvalue); free(bluevalue); free(ximageinfo); + return NULL; } @@ -291,6 +294,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, while ((bluebottom < 256) && (bluebottom < bluetop)) bluevalue[bluebottom++] = xcolor.pixel & visual->blue_mask; } + break; } @@ -421,6 +425,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, default: Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed"); SetError(error, "display class not supported"); + return NULL; } @@ -467,6 +472,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, dst_ptr += display_bytes_per_pixel; } } + break; } @@ -486,14 +492,17 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, dst_ptr += display_bytes_per_pixel; } } + break; } default: Error(ERR_RETURN, "RGB or TrueColor image needed"); SetError(error, "image type not supported"); + return NULL; } + break; } @@ -517,12 +526,14 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, } } } + break; } default: Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed"); SetError(error, "display class not supported"); + return NULL; } @@ -544,11 +555,9 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, XPutImage(ximageinfo->display, ximageinfo->pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); - free(ximage->data); - ximage->data = NULL; XDestroyImage(ximage); - return(ximageinfo); + return ximageinfo; } void freeXImage(Image *image, XImageInfo *ximageinfo) @@ -593,7 +602,11 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, /* convert image structure to X11 Pixmap */ if (!(ximageinfo = Image_to_Pixmap(display, screen, visual, window, gc, depth, image))) + { + freeImage(image); + return PCX_OtherError; + } /* if a private colormap has been created, install it */ if (ximageinfo->cmap != DefaultColormap(display, screen)) @@ -613,6 +626,10 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, *pixmap = ximageinfo->pixmap; *pixmap_mask = ximageinfo->pixmap_mask; + /* free generic image and ximageinfo after native Pixmap has been created */ + free(ximageinfo); + freeImage(image); + return PCX_Success; } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index c59749ff..b344ba6f 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1206,6 +1206,17 @@ boolean FileIsMusic(char *basename) return FALSE; } +boolean FileIsArtworkType(char *basename, int type) +{ + if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) || + (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) || + (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename))) + return TRUE; + + return FALSE; +} + + /* ========================================================================= */ /* functions only needed for non-Unix (non-command-line) systems */ /* ========================================================================= */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 3dd380b1..499bd425 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -114,6 +114,7 @@ char getCharFromKey(Key); boolean FileIsGraphic(char *); boolean FileIsSound(char *); boolean FileIsMusic(char *); +boolean FileIsArtworkType(char *, int); #if !defined(PLATFORM_UNIX) void initErrorFile(); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 57ba732a..6ad11351 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -84,6 +84,27 @@ static char *levelclass_desc[NUM_LEVELCLASS_DESC] = #define MAX_COOKIE_LEN 256 +#define ARTWORKINFO_FILENAME(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + GRAPHICSINFO_FILENAME : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + SOUNDSINFO_FILENAME : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + MUSICINFO_FILENAME : "") + +#define ARTWORK_DIRECTORY(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + GRAPHICS_DIRECTORY : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + SOUNDS_DIRECTORY : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + MUSIC_DIRECTORY : "") + +#define OPTIONS_ARTWORK_DIRECTORY(type) ((type) == TREE_TYPE_GRAPHICS_DIR ? \ + options.graphics_directory : \ + (type) == TREE_TYPE_SOUNDS_DIR ? \ + options.sounds_directory : \ + (type) == TREE_TYPE_MUSIC_DIR ? \ + options.music_directory : "") + /* ------------------------------------------------------------------------- */ /* file functions */ @@ -167,23 +188,27 @@ static char *getLevelSetupDir(char *level_subdir) return levelsetup_dir; } -static char *getCurrentLevelDir() +static char *getLevelDirFromTreeInfo(TreeInfo *node) { static char *level_dir = NULL; + if (node == NULL) + return options.level_directory; + if (level_dir) free(level_dir); - if (leveldir_current == NULL) - return options.level_directory; - - level_dir = getPath2((leveldir_current->user_defined ? - getUserLevelDir(NULL) : options.level_directory), - leveldir_current->fullpath); + level_dir = getPath2((node->user_defined ? getUserLevelDir(NULL) : + options.level_directory), node->fullpath); return level_dir; } +static char *getCurrentLevelDir() +{ + return getLevelDirFromTreeInfo(leveldir_current); +} + static char *getDefaultGraphicsDir(char *graphics_subdir) { static char *graphics_dir = NULL; @@ -1590,14 +1615,9 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, char *directory_name, int type) { char *directory_path = getPath2(base_directory, directory_name); - char *filename = - getPath2(directory_path, - (type == TREE_TYPE_GRAPHICS_DIR ? GRAPHICSINFO_FILENAME : - type == TREE_TYPE_SOUNDS_DIR ? SOUNDSINFO_FILENAME : - type == TREE_TYPE_MUSIC_DIR ? MUSICINFO_FILENAME : "")); + char *filename = getPath2(directory_path, ARTWORKINFO_FILENAME(type)); struct SetupFileList *setup_file_list = NULL; TreeInfo *artwork_new = NULL; - char *check_dir = NULL; int i; if (access(filename, F_OK) == 0) /* file exists */ @@ -1615,9 +1635,7 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, { char *entry_name = dir_entry->d_name; - if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(entry_name)) || - (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(entry_name)) || - (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(entry_name))) + if (FileIsArtworkType(entry_name, type)) { valid_file_found = TRUE; break; @@ -1687,11 +1705,8 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, artwork_new->fullpath = getPath2(node_parent->fullpath, directory_name); } - check_dir = (type == TREE_TYPE_GRAPHICS_DIR ? options.graphics_directory : - type == TREE_TYPE_SOUNDS_DIR ? options.sounds_directory : - type == TREE_TYPE_MUSIC_DIR ? options.music_directory : ""); artwork_new->user_defined = - (artwork_new->basepath == check_dir ? FALSE : TRUE); + (artwork_new->basepath == OPTIONS_ARTWORK_DIRECTORY(type) ? FALSE : TRUE); /* (may use ".sort_priority" from "setup_file_list" above) */ artwork_new->color = LEVELCOLOR(artwork_new); @@ -1745,12 +1760,7 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, if ((dir = opendir(base_directory)) == NULL) { - if ((type == TREE_TYPE_GRAPHICS_DIR && - base_directory == options.graphics_directory) || - (type == TREE_TYPE_SOUNDS_DIR && - base_directory == options.sounds_directory) || - (type == TREE_TYPE_MUSIC_DIR && - base_directory == options.music_directory)) + if (base_directory == OPTIONS_ARTWORK_DIRECTORY(type)) Error(ERR_WARN, "cannot read directory '%s'", base_directory); return; } @@ -1858,53 +1868,50 @@ void LoadArtworkInfo() #endif } -void LoadArtworkInfoFromLevelInfo(TreeInfo *node) +void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, + LevelDirTree *level_node) { - while (node) + /* recursively check all level directories for artwork sub-directories */ + + while (level_node) { - char *path = getPath3((node->user_defined ? - getUserLevelDir(NULL) : options.level_directory), - node->fullpath, SOUNDS_DIRECTORY); + char *path = getPath2(getLevelDirFromTreeInfo(level_node), + ARTWORK_DIRECTORY((*artwork_node)->type)); #if 0 - if (!node->parent_link) + if (!level_node->parent_link) printf("CHECKING '%s' ['%s', '%s'] ...\n", path, - node->filename, node->name); + level_node->filename, level_node->name); #endif - if (!node->parent_link) + if (!level_node->parent_link) { - TreeInfo *topnode_last = artwork.snd_first; + TreeInfo *topnode_last = *artwork_node; - LoadArtworkInfoFromArtworkDir(&artwork.snd_first, NULL, - path, - TREE_TYPE_SOUNDS_DIR); + LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path, + (*artwork_node)->type); - if (topnode_last != artwork.snd_first) + if (topnode_last != *artwork_node) { -#if 0 - printf("NEW NODE: '%s'\n", artwork.snd_first->name); -#endif - - free(artwork.snd_first->name); - free(artwork.snd_first->name_sorting); - free(artwork.snd_first->name_short); + free((*artwork_node)->name); + free((*artwork_node)->name_sorting); + free((*artwork_node)->name_short); - artwork.snd_first->name = getStringCopy(node->name); - artwork.snd_first->name_sorting = getStringCopy(node->name); - artwork.snd_first->name_short = getStringCopy(node->filename); + (*artwork_node)->name = getStringCopy(level_node->name); + (*artwork_node)->name_sorting = getStringCopy(level_node->name); + (*artwork_node)->name_short = getStringCopy(level_node->filename); - artwork.snd_first->sort_priority = node->sort_priority; - artwork.snd_first->color = LEVELCOLOR(artwork.snd_first); + (*artwork_node)->sort_priority = level_node->sort_priority; + (*artwork_node)->color = LEVELCOLOR((*artwork_node)); } } free(path); - if (node->node_group != NULL) - LoadArtworkInfoFromLevelInfo(node->node_group); + if (level_node->node_group != NULL) + LoadArtworkInfoFromLevelInfo(artwork_node, level_node->node_group); - node = node->next; + level_node = level_node->next; } } @@ -1912,12 +1919,18 @@ void LoadLevelArtworkInfo() { DrawInitText("Looking for custom level artwork:", 120, FC_GREEN); - LoadArtworkInfoFromLevelInfo(leveldir_first); + LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, leveldir_first); + LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first); + LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first); + sortTreeInfo(&artwork.gfx_first, compareTreeInfoEntries); sortTreeInfo(&artwork.snd_first, compareTreeInfoEntries); + sortTreeInfo(&artwork.mus_first, compareTreeInfoEntries); #if 1 + dumpTreeInfo(artwork.gfx_first, 0); dumpTreeInfo(artwork.snd_first, 0); + dumpTreeInfo(artwork.mus_first, 0); #endif } diff --git a/src/libgame/system.h b/src/libgame/system.h index 1a130ee0..b21f866c 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -381,6 +381,7 @@ struct TreeInfo typedef struct TreeInfo TreeInfo; typedef struct TreeInfo LevelDirTree; +typedef struct TreeInfo ArtworkDirTree; typedef struct TreeInfo GraphicsDirTree; typedef struct TreeInfo SoundsDirTree; typedef struct TreeInfo MusicDirTree; diff --git a/src/libgame/x11.c b/src/libgame/x11.c index 394350a6..7d45a493 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -255,10 +255,6 @@ Bitmap *X11LoadImage(char *filename) char *error = "Read_PCX_to_Pixmap(): %s '%s'"; int pcx_err; -#if defined(PLATFORM_MSDOS) - rest(100); -#endif - pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, filename, &new_bitmap->drawable, &new_bitmap->clip_mask); switch(pcx_err) diff --git a/src/timestamp.h b/src/timestamp.h index 3dd66bf7..062fe59a 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-05-27 23:07]" +#define COMPILE_DATE_STRING "[2002-05-31 17:39]"