mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r27687) -Fix: RailtypeInfo::alternate_labels leaked when reloading NewGRF. (adf88)
This commit is contained in:
parent
10293c5fb1
commit
3ee06b036e
|
@ -113,7 +113,8 @@ typedef SmallVector<RailTypeLabel, 4> RailTypeLabelList;
|
||||||
/**
|
/**
|
||||||
* This struct contains all the info that is needed to draw and construct tracks.
|
* This struct contains all the info that is needed to draw and construct tracks.
|
||||||
*/
|
*/
|
||||||
struct RailtypeInfo {
|
class RailtypeInfo {
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Struct containing the main sprites. @note not all sprites are listed, but only
|
* Struct containing the main sprites. @note not all sprites are listed, but only
|
||||||
* the ones used directly in the code
|
* the ones used directly in the code
|
||||||
|
|
|
@ -47,8 +47,6 @@ RailtypeInfo _railtypes[RAILTYPE_END];
|
||||||
RailType _sorted_railtypes[RAILTYPE_END];
|
RailType _sorted_railtypes[RAILTYPE_END];
|
||||||
uint8 _sorted_railtypes_size;
|
uint8 _sorted_railtypes_size;
|
||||||
|
|
||||||
assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
|
|
||||||
|
|
||||||
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
|
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
|
||||||
enum SignalOffsets {
|
enum SignalOffsets {
|
||||||
SIGNAL_TO_SOUTHWEST,
|
SIGNAL_TO_SOUTHWEST,
|
||||||
|
@ -66,8 +64,11 @@ enum SignalOffsets {
|
||||||
*/
|
*/
|
||||||
void ResetRailTypes()
|
void ResetRailTypes()
|
||||||
{
|
{
|
||||||
memset(_railtypes, 0, sizeof(_railtypes));
|
assert_compile(lengthof(_original_railtypes) <= lengthof(_railtypes));
|
||||||
memcpy(_railtypes, _original_railtypes, sizeof(_original_railtypes));
|
|
||||||
|
uint i = 0;
|
||||||
|
for (; i < lengthof(_original_railtypes); i++) _railtypes[i] = _original_railtypes[i];
|
||||||
|
for (; i < lengthof(_railtypes); i++) _railtypes[i] = RailtypeInfo(); // zero-init
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolveRailTypeGUISprites(RailtypeInfo *rti)
|
void ResolveRailTypeGUISprites(RailtypeInfo *rti)
|
||||||
|
@ -151,11 +152,9 @@ RailType AllocateRailType(RailTypeLabel label)
|
||||||
|
|
||||||
if (rti->label == 0) {
|
if (rti->label == 0) {
|
||||||
/* Set up new rail type */
|
/* Set up new rail type */
|
||||||
memcpy(rti, &_railtypes[RAILTYPE_RAIL], sizeof(*rti));
|
*rti = _railtypes[RAILTYPE_RAIL];
|
||||||
rti->label = label;
|
rti->label = label;
|
||||||
/* Clear alternate label list. Can't use Reset() here as that would free
|
rti->alternate_labels.Clear();
|
||||||
* the data pointer of RAILTYPE_RAIL and not our new rail type. */
|
|
||||||
new (&rti->alternate_labels) RailTypeLabelList;
|
|
||||||
|
|
||||||
/* Make us compatible with ourself. */
|
/* Make us compatible with ourself. */
|
||||||
rti->powered_railtypes = (RailTypes)(1 << rt);
|
rti->powered_railtypes = (RailTypes)(1 << rt);
|
||||||
|
|
Loading…
Reference in New Issue