mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22175) -Fix: [NewGRF] memory leak if a station newgrf contains prop 09 twice for the same station id
This commit is contained in:
parent
91ddf07c80
commit
261b34b705
|
@ -1199,7 +1199,6 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
|
||||||
case 0x09: // Define sprite layout
|
case 0x09: // Define sprite layout
|
||||||
statspec->tiles = buf->ReadExtendedByte();
|
statspec->tiles = buf->ReadExtendedByte();
|
||||||
statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
|
statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
|
||||||
statspec->copied_renderdata = false;
|
|
||||||
|
|
||||||
for (uint t = 0; t < statspec->tiles; t++) {
|
for (uint t = 0; t < statspec->tiles; t++) {
|
||||||
DrawTileSprites *dts = &statspec->renderdata[t];
|
DrawTileSprites *dts = &statspec->renderdata[t];
|
||||||
|
@ -1208,7 +1207,12 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
|
||||||
dts->seq = NULL;
|
dts->seq = NULL;
|
||||||
dts->ground.sprite = buf->ReadWord();
|
dts->ground.sprite = buf->ReadWord();
|
||||||
dts->ground.pal = buf->ReadWord();
|
dts->ground.pal = buf->ReadWord();
|
||||||
if (dts->ground.sprite == 0) continue;
|
if (dts->ground.sprite == 0 && dts->ground.pal == 0) {
|
||||||
|
extern const DrawTileSprites _station_display_datas_rail[8];
|
||||||
|
dts->ground = _station_display_datas_rail[t % 8].ground;
|
||||||
|
dts->seq = CopyDrawTileSeqStruct(_station_display_datas_rail[t % 8].seq);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (HasBit(dts->ground.pal, 15)) {
|
if (HasBit(dts->ground.pal, 15)) {
|
||||||
/* Use sprite from Action 1 */
|
/* Use sprite from Action 1 */
|
||||||
ClrBit(dts->ground.pal, 15);
|
ClrBit(dts->ground.pal, 15);
|
||||||
|
@ -1254,8 +1258,11 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
|
||||||
}
|
}
|
||||||
|
|
||||||
statspec->tiles = srcstatspec->tiles;
|
statspec->tiles = srcstatspec->tiles;
|
||||||
statspec->renderdata = srcstatspec->renderdata;
|
statspec->renderdata = MallocT<DrawTileSprites>(statspec->tiles);
|
||||||
statspec->copied_renderdata = true;
|
for (uint t = 0; t < statspec->tiles; t++) {
|
||||||
|
statspec->renderdata[t].ground = srcstatspec->renderdata[t].ground;
|
||||||
|
statspec->renderdata[t].seq = CopyDrawTileSeqStruct(srcstatspec->renderdata[t].seq);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7050,13 +7057,10 @@ static void ResetCustomStations()
|
||||||
if (stations[i] == NULL) continue;
|
if (stations[i] == NULL) continue;
|
||||||
StationSpec *statspec = stations[i];
|
StationSpec *statspec = stations[i];
|
||||||
|
|
||||||
/* Release renderdata, if it wasn't copied from another custom station spec */
|
for (uint t = 0; t < statspec->tiles; t++) {
|
||||||
if (!statspec->copied_renderdata) {
|
free((void*)statspec->renderdata[t].seq);
|
||||||
for (uint t = 0; t < statspec->tiles; t++) {
|
|
||||||
free((void*)statspec->renderdata[t].seq);
|
|
||||||
}
|
|
||||||
free(statspec->renderdata);
|
|
||||||
}
|
}
|
||||||
|
free(statspec->renderdata);
|
||||||
|
|
||||||
/* Release platforms and layouts */
|
/* Release platforms and layouts */
|
||||||
if (!statspec->copied_layouts) {
|
if (!statspec->copied_layouts) {
|
||||||
|
|
|
@ -78,7 +78,6 @@ struct StationSpec {
|
||||||
*/
|
*/
|
||||||
uint tiles;
|
uint tiles;
|
||||||
DrawTileSprites *renderdata; ///< Array of tile layouts.
|
DrawTileSprites *renderdata; ///< Array of tile layouts.
|
||||||
bool copied_renderdata;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cargo threshold for choosing between little and lots of cargo
|
* Cargo threshold for choosing between little and lots of cargo
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
#include "landscape.h"
|
#include "landscape.h"
|
||||||
#include "spritecache.h"
|
#include "spritecache.h"
|
||||||
|
#include "core/alloc_func.hpp"
|
||||||
|
#include "core/mem_func.hpp"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,3 +110,17 @@ void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create a copy of an existing DrawTileSeqStruct array. */
|
||||||
|
const DrawTileSeqStruct *CopyDrawTileSeqStruct(const DrawTileSeqStruct *dtss)
|
||||||
|
{
|
||||||
|
const DrawTileSeqStruct *element;
|
||||||
|
|
||||||
|
size_t count = 1; // 1 for the terminator
|
||||||
|
foreach_draw_tile_seq(element, dtss) count++;
|
||||||
|
|
||||||
|
DrawTileSeqStruct *copy = MallocT<DrawTileSeqStruct>(count);
|
||||||
|
MemCpyT(copy, dtss, count);
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ struct DrawTileSeqStruct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DrawTileSeqStruct *CopyDrawTileSeqStruct(const DrawTileSeqStruct *dtss);
|
||||||
|
|
||||||
/** Ground palette sprite of a tile, together with its child sprites */
|
/** Ground palette sprite of a tile, together with its child sprites */
|
||||||
struct DrawTileSprites {
|
struct DrawTileSprites {
|
||||||
PalSpriteID ground; ///< Palette and sprite for the ground
|
PalSpriteID ground; ///< Palette and sprite for the ground
|
||||||
|
|
|
@ -791,7 +791,7 @@ static const DrawTileSeqStruct _station_display_datas_waypoint_Y[] = {
|
||||||
#define TILE_SPRITE_LINE(img, dtss) { {img, PAL_NONE}, dtss },
|
#define TILE_SPRITE_LINE(img, dtss) { {img, PAL_NONE}, dtss },
|
||||||
#define TILE_SPRITE_NULL() { {0, 0}, NULL },
|
#define TILE_SPRITE_NULL() { {0, 0}, NULL },
|
||||||
|
|
||||||
static const DrawTileSprites _station_display_datas_rail[] = {
|
extern const DrawTileSprites _station_display_datas_rail[] = {
|
||||||
TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_0)
|
TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_0)
|
||||||
TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_1)
|
TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_1)
|
||||||
TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_2)
|
TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_2)
|
||||||
|
|
Loading…
Reference in New Issue