diff --git a/src/am_map.c b/src/am_map.c index d90147e28..a0b2362cc 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -1353,13 +1353,16 @@ void AM_Drawer(void) if (!followplayer) AM_drawCrosshair(XHAIRCOLORS); } -UINT8 *AM_MinimapGenerate(INT32 wh) +minigen_t *AM_MinimapGenerate(INT32 wh) { - UINT8 *buf = NULL; + static minigen_t ret = {0}; if (automapactive) return NULL; + ret.w = ret.h = 0; + ret.buf = NULL; + am_minigen = true; AM_drawFline = AM_drawFline_soft; // yes, even in GL @@ -1396,9 +1399,9 @@ UINT8 *AM_MinimapGenerate(INT32 wh) old_m_w = m_w; old_m_h = m_h; - buf = malloc(2 + (f_w*f_h)); - - am_buf = buf+2; + ret.w = f_w; + ret.h = f_h; + am_buf = ret.buf = malloc((f_w*f_h)); //AM_clearFB(BACKGROUND); memset(am_buf, 0xff, (f_w*f_h)); @@ -1411,7 +1414,5 @@ UINT8 *AM_MinimapGenerate(INT32 wh) am_minigen = false; - buf[0] = (UINT8)f_w; - buf[1] = (UINT8)f_h; - return buf; + return &ret; } diff --git a/src/am_map.h b/src/am_map.h index be32f342c..c3f80e5ad 100644 --- a/src/am_map.h +++ b/src/am_map.h @@ -48,8 +48,14 @@ void AM_Start(void); // Called to force the automap to quit if the level is completed while it is up. void AM_Stop(void); +struct minigen_t +{ + INT32 w, h; + UINT8 *buf; +}; + // Minimap generation -UINT8 *AM_MinimapGenerate(INT32 wh); +minigen_t *AM_MinimapGenerate(INT32 wh); #ifdef __cplusplus } // extern "C" diff --git a/src/m_misc.c b/src/m_misc.c index 49f8f2ddc..21cc1287d 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1754,7 +1754,7 @@ void M_MinimapGenerate(void) #ifdef USE_PNG char *filepath = va(pandf, srb2home, "MINIMAP.png"); boolean ret = false; - UINT8 *linear = NULL; + minigen_t *minigen = NULL; INT32 wh = 100; if (gamestate != GS_LEVEL) @@ -1763,17 +1763,17 @@ void M_MinimapGenerate(void) return; } - linear = AM_MinimapGenerate(wh); + minigen = AM_MinimapGenerate(wh); - if (linear == NULL) + if (minigen == NULL || minigen->buf == NULL) goto failure; M_CreateScreenShotPalette(); - ret = M_SavePNG(filepath, linear+2, linear[0], linear[1], screenshot_palette); + ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); failure: - if (linear != NULL) - free(linear); + if (minigen->buf != NULL) + free(minigen->buf); if (ret) { diff --git a/src/typedef.h b/src/typedef.h index 1ca433cb9..f33ee2f3b 100644 --- a/src/typedef.h +++ b/src/typedef.h @@ -26,6 +26,7 @@ extern "C" { // am_map.h TYPEDEF (fpoint_t); TYPEDEF (fline_t); +TYPEDEF (minigen_t); // command.h TYPEDEF (vsbuf_t);