diff --git a/sc2/src/libs/graphics/cmap.c b/sc2/src/libs/graphics/cmap.c index a99809aea..53cd13fbe 100644 --- a/sc2/src/libs/graphics/cmap.c +++ b/sc2/src/libs/graphics/cmap.c @@ -64,6 +64,10 @@ static int mapcount; static Mutex maplock; +static void release_colormap (TFB_ColorMap *map); +static void delete_colormap (TFB_ColorMap *map); + + void InitColorMaps (void) { @@ -84,13 +88,23 @@ InitColorMaps (void) void UninitColorMaps (void) { + int i; TFB_ColorMap *next; + for (i = 0; i < MAX_COLORMAPS; ++i) + { + TFB_ColorMap *map = colormaps[i]; + if (!map) + continue; + release_colormap (map); + colormaps[i] = 0; + } + // free spares - for ( ; poolhead; poolhead = next) + for ( ; poolhead; poolhead = next, --poolcount) { next = poolhead->next; - HFree (poolhead); + delete_colormap (poolhead); } DestroyMutex (fadeLock); @@ -155,6 +169,13 @@ clone_colormap (TFB_ColorMap *from, int index) return map; } +static void +delete_colormap (TFB_ColorMap *map) +{ + FreeNativePalette (map->palette); + HFree (map); +} + static inline void free_colormap (TFB_ColorMap *map) { @@ -172,8 +193,7 @@ free_colormap (TFB_ColorMap *map) } else { // don't need any more spares - FreeNativePalette (map->palette); - HFree (map); + delete_colormap (map); } } @@ -193,7 +213,7 @@ get_colormap (int index) return map; } -static inline void +static void release_colormap (TFB_ColorMap *map) { if (!map) diff --git a/sc2/src/libs/graphics/dcqueue.c b/sc2/src/libs/graphics/dcqueue.c index 7fa4db38d..f57891646 100644 --- a/sc2/src/libs/graphics/dcqueue.c +++ b/sc2/src/libs/graphics/dcqueue.c @@ -635,6 +635,13 @@ TFB_PurgeDanglingGraphics (void) HFree (data); break; } + case TFB_DRAWCOMMANDTYPE_IMAGE: + { + TFB_ColorMap *cmap = DC.data.image.colormap; + if (cmap) + TFB_ReturnColorMap (cmap); + break; + } case TFB_DRAWCOMMANDTYPE_SENDSIGNAL: { ClearSemaphore (DC.data.sendsignal.sem); diff --git a/sc2/src/libs/graphics/gfx_common.c b/sc2/src/libs/graphics/gfx_common.c index e357d18c6..405f61447 100644 --- a/sc2/src/libs/graphics/gfx_common.c +++ b/sc2/src/libs/graphics/gfx_common.c @@ -99,7 +99,7 @@ UnbatchGraphics (void) been processed. */ void -FlushGraphics () +FlushGraphics (void) { TFB_DrawScreen_WaitForSignal (); } diff --git a/sc2/src/uqm.c b/sc2/src/uqm.c index 2a8074d35..f6c4630a9 100644 --- a/sc2/src/uqm.c +++ b/sc2/src/uqm.c @@ -467,9 +467,10 @@ main (int argc, char *argv[]) // Not yet: TFB_UninitInput (); unInitAudio (); uninit_communication (); - UninitColorMaps (); // TODO: Merge into TFB_UninitGraphics when it goes live TFB_PurgeDanglingGraphics (); + // Purge above refers to colormaps which have to be still up + UninitColorMaps (); // Not yet: TFB_UninitGraphics (); #ifdef NETPLAY