mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r11819) -Fix: do not access the Vehicle struct that has been already deleted when removing crashed train
This commit is contained in:
parent
ac528411df
commit
712d4b6259
@ -3122,22 +3122,26 @@ static void DeleteLastWagon(Vehicle *v)
|
|||||||
BeginVehicleMove(v);
|
BeginVehicleMove(v);
|
||||||
EndVehicleMove(v);
|
EndVehicleMove(v);
|
||||||
|
|
||||||
|
/* 'v' shouldn't be accessed after it has been deleted */
|
||||||
|
TrackBits track = v->u.rail.track;
|
||||||
|
TileIndex tile = v->tile;
|
||||||
|
|
||||||
delete v;
|
delete v;
|
||||||
|
|
||||||
if (v->u.rail.track != TRACK_BIT_DEPOT && v->u.rail.track != TRACK_BIT_WORMHOLE)
|
if (track != TRACK_BIT_DEPOT && track != TRACK_BIT_WORMHOLE)
|
||||||
SetSignalsOnBothDir(v->tile, (Track)(FIND_FIRST_BIT(v->u.rail.track)));
|
SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)));
|
||||||
|
|
||||||
/* Check if the wagon was on a road/rail-crossing and disable it if no
|
/* Check if the wagon was on a road/rail-crossing and disable it if no
|
||||||
* others are on it */
|
* others are on it */
|
||||||
DisableTrainCrossing(v->tile);
|
DisableTrainCrossing(tile);
|
||||||
|
|
||||||
if (v->u.rail.track == TRACK_BIT_WORMHOLE) { // inside a tunnel / bridge
|
if (track == TRACK_BIT_WORMHOLE) { // inside a tunnel / bridge
|
||||||
TileIndex endtile = GetOtherTunnelBridgeEnd(v->tile);
|
TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
|
||||||
|
|
||||||
if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy
|
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return; // tunnel / bridge is busy
|
||||||
|
|
||||||
/* v->direction is "random", so it cannot be used to determine the direction of the track */
|
/* v->direction is "random", so it cannot be used to determine the direction of the track */
|
||||||
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR);
|
UpdateSignalsOnSegment(tile, INVALID_DIAGDIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user