mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r17605) -Fix [FS#3218]: [NewGRF] Crash when defining the same tile in a tile layout twice
This commit is contained in:
parent
9da24054b2
commit
3dd202ba1c
@ -2148,6 +2148,25 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the industry layout; e.g. to prevent duplicate tiles.
|
||||||
|
* @param layout the layout to check
|
||||||
|
* @param size the size of the layout
|
||||||
|
* @return true if the layout is deemed valid
|
||||||
|
*/
|
||||||
|
static bool ValidateIndustryLayout(const IndustryTileTable *layout, int size)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < size - 1; i++) {
|
||||||
|
for (int j = i + 1; j < size; j++) {
|
||||||
|
if (layout[i].ti.x == layout[j].ti.x &&
|
||||||
|
layout[i].ti.y == layout[j].ti.y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
|
static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
|
||||||
{
|
{
|
||||||
byte *buf = *bufp;
|
byte *buf = *bufp;
|
||||||
@ -2279,9 +2298,17 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
|
|||||||
itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
|
itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ValidateIndustryLayout(copy_from, size)) {
|
||||||
|
/* The industry layout was not valid, so skip this one. */
|
||||||
|
grfmsg(1, "IndustriesChangeInfo: Invalid industry layout for industry id %u. Ignoring", indid);
|
||||||
|
indsp->num_table--;
|
||||||
|
j--;
|
||||||
|
} else {
|
||||||
tile_table[j] = CallocT<IndustryTileTable>(size);
|
tile_table[j] = CallocT<IndustryTileTable>(size);
|
||||||
memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
|
memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Install final layout construction in the industry spec */
|
/* Install final layout construction in the industry spec */
|
||||||
indsp->table = tile_table;
|
indsp->table = tile_table;
|
||||||
SetBit(indsp->cleanup_flag, 1);
|
SetBit(indsp->cleanup_flag, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user